Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/index.ts:12:22 - error TS2307: Cannot find module './schema.graphql' or its corresponding type declarations #90

Open
Darfion opened this issue Nov 9, 2021 · 2 comments

Comments

@Darfion
Copy link

Darfion commented Nov 9, 2021

hi I want to import a graphql file. but for some reason i am getting error

\node_modules\ts-node\src\index.ts:750
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/index.ts:12:22 - error TS2307: Cannot find module './schema.graphql' or its corresponding type declarations.

12 import typeDefs from "./schema.graphql";
                        ~~~~~~~~~~~~~~~~~~

how do i do the import

import typeDefs from "./schema.graphql";

graphql.d.ts

declare module "*.graphql" {
  import { DocumentNode } from "graphql";

  const value: DocumentNode;
  export = value;
}

.babelrc

{
  "plugins": ["import-graphql"]
}

full code can be viewed here

@webjay
Copy link

webjay commented Oct 25, 2022

this works for me:

const importGraphql = ['import-graphql', { emitDeclarations: true }];
const plugins = [importGraphql, ...etc];

@alburdette619
Copy link

alburdette619 commented Dec 18, 2023

@webjay's comment worked, but the typings for DocumentNode for apollo vs what this outputs isn't working.

First it throws this typing issue:

 Types of property 'kind' are incompatible.
      Type '"Document"' is not assignable to type 'Kind.DOCUMENT'

And if you fix that it says loc is not typed correctly:

Types of property 'loc' are incompatible.
      Type '...' is missing the following properties from type 'Location': startToken, endToken, toJSON, [Symbol.toStringTag]

I've tried setting up my graphql.d.ts to use both the graphql & @apollo/client verions but neither satisfies the call to useQuery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants