babel-plugin-import-graphql
babel-plugin-import-graphql copied to clipboard
src/index.ts:12:22 - error TS2307: Cannot find module './schema.graphql' or its corresponding type declarations
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
this works for me:
const importGraphql = ['import-graphql', { emitDeclarations: true }];
const plugins = [importGraphql, ...etc];
@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
.