0

I'm working in a SvelteKit project and want to use gql codegen, but all queries are typed as unknown.

Ts file:

import { graphql } from '$lib/gql/index.js';

export const getPostById = graphql(`
    query GET_ARTICLE($id: bigint!) {
        articles_by_pk(id: $id) {
            content
            created_at
            slug
            updated_at
            title
        }
    }
`);

codegen.ts


import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  overwrite: true,
  schema: "https:...myap",
  debug: true,
  verbose:true,
  watch:true,
  ignoreNoDocuments: true,
  emitLegacyCommonJSImports: false,
  documents:["./src/**/*.svelte", "./src/**/*.ts"],
  generates: {
    "src/lib/gql/": {
      preset: 'client',
      plugins: []
    },
    "./graphql.schema.json": {
      plugins: ["introspection"]
    }
  }
};

export default config;

The const documents = []; in the gql.ts file is empty (I think it shouldn't).

The package.json script includes: "codegen": "graphql-codegen-esm --config codegen.ts"

Running the script does not throw any errors. I have no idea where to start looking.

Niro
  • 142
  • 9
  • In the generated file, there should be a type definition for the `graphql` function. It uses TypeScripts overload syntax. If there is not one case that looks roughly linke this: `function graphql(document: "\n query GET_ARTICLE($id: bigint!) {\n ..."): TypedDocumentNode<...>`, then your codegen script does not seem to work. Check, if your glob patterns correctly match your file`. – Herku May 30 '23 at 20:59
  • Im on sveltekit wich uses "=" in its folder names. The code generator ignores these folders. Issue : https://github.com/dotansimha/graphql-code-generator/issues/8978 – Niro May 31 '23 at 14:18

0 Answers0