graphqlapollo-clientgraphql-codegen

CodeGen graphql returns type unkown


Here is my codeGen file

const config: CodegenConfig = {
  schema: "http://localhost:3000/graphql",
  documents: ["core/shared/gql/**/*.ts"],
  // ignoreNoDocuments: true, // for better experience with the watcher
  generates: {
    "./core/utils/generator/": {
      preset: "client",
    },
  },
};

Here is my operation

export const createsManyAnswer = graphql(`
  mutation (
    $answerinput: [AnswerInput!]!
  ) {
    createsManyAnswer(
      createAnswerInput: { Answers: $answerinput }
    ) {
      Assessment
    }
  }
`);

Here is the code generator graphql output:

export function graphql(source: string): unknown;

export function graphql(source: string) {
  return (documents as any)[source] ?? {};
}

I've already double checked that the document paths are referenced correctly. I've already checked similar previous post but none of them solve my problem


Solution

  • It's so dumb but the solution is to always set names to the operations. In my case I needed to add a name for the mutation operation.

    Otherwise the code gen skip those operations! It must be documented somewhere!

    export const createsManyAnswer = graphql(`
      mutation CreatesManyAnswer(
        $answerinput: [AnswerInput!]!
      ) {
        createsManyAnswer(
          createAnswerInput: { Answers: $answerinput }
        ) {
          Assessment
        }
      }
    `);