typescriptgraphqlapollo-clientgraphql-codegen

Graphql codegen configuration does not load documents with Glob Expression


My API is written with TypeScript/Apollo and I am able to run queries/mutations on http://localhost:4000/graphql. My front-end is with Next.js and Apollo client. I use GraphQL Codegenerator to generate the client-side code I need.

I am using:

"@graphql-codegen/cli": "1.20.1",
"@graphql-codegen/typescript": "1.20.2",
"@graphql-codegen/typescript-operations": "1.17.14",
"@graphql-codegen/typescript-react-apollo": "2.2.1",

and my codegen.yml file is

overwrite: true
schema: "http://localhost:4000/graphql"
documents: "src/graphql/**/*.graphql"
generates:
  src/generated/graphql.tsx:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-apollo"

The script I run when I change my API resolvers is "gen": "graphql-codegen --config codegen.yml"

If I do run this code, I get the error:

  ✖ src/generated/graphql.tsx
    Error: 
          Unable to find any GraphQL type definitions for the following pointers:
        
              - src/graphql/**/*.graphql

but If set my codegen.yml file as follows it works (and I tested a query in one of the component, I can access data):

overwrite: true
schema: "http://localhost:4000/graphql"
documents:
  - "src/graphql/fragments/RecipeSnippet.graphql"
  - "src/graphql/fragments/RegularError.graphql"
  - "src/graphql/fragments/RegularUser.graphql"
  - "src/graphql/fragments/RegularUserResponse.graphql"
  - "src/graphql/mutations/createRecipe.graphql"
  - "src/graphql/mutations/deleteRecipe.graphql"
  - "src/graphql/mutations/login.graphql"
  - "src/graphql/mutations/logout.graphql"
  - "src/graphql/mutations/register.graphql"
  - "src/graphql/mutations/updateRecipe.graphql"
  - "src/graphql/queries/me.graphql"
  - "src/graphql/queries/recipe.graphql"
  - "src/graphql/queries/recipes.graphql"
generates:
  src/generated/graphql.tsx:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-apollo"

I am not sure exactly what I am doing wrong and what is even weirder is that it used to work. I remember updating my deps recently though. I saw and tried a few other answers like this one or this one but to no avail :(


Solution

  • I met the same issue recently. And I change the codegen.yml to solve this issue. You can try to modify your codegen.yml like this: My API is written with TypeScript/Apollo and I am able to run queries/mutations on http://localhost:4000/graphql. My front-end is with Next.js and Apollo client. I use GraphQL Codegenerator to generate the client-side code I need.

    I am using:

    "@graphql-codegen/cli": "1.20.1",
    "@graphql-codegen/typescript": "1.20.2",
    "@graphql-codegen/typescript-operations": "1.17.14",
    "@graphql-codegen/typescript-react-apollo": "2.2.1",
    

    and my codegen.yml file is:

    overwrite: true
    schema: "http://localhost:4000/graphql"
    documents: "src/graphql/**/*.graphql"
    generates:
      src/generated/graphql.tsx:
        plugins:
          - "typescript"
          - "typescript-operations"
          - "typescript-react-apollo"
    The script I run when I change my API resolvers is "gen": "graphql-codegen --config codegen.yml"
    

    If I do run this code, I get the error:

      ✖ src/generated/graphql.tsx
        Error: 
              Unable to find any GraphQL type definitions for the following pointers:
            
                  - src/graphql/**/*.graphql
    but If set my codegen.yml file as follows it works (and I tested a query in one of the component, I can access data):
    
    overwrite: true
    schema: "http://localhost:4000/graphql"
    documents:
      - "src/graphql/fragments/RecipeSnippet.graphql"
      - "src/graphql/fragments/RegularError.graphql"
      - "src/graphql/fragments/RegularUser.graphql"
      - "src/graphql/fragments/RegularUserResponse.graphql"
      - "src/graphql/mutations/createRecipe.graphql"
      - "src/graphql/mutations/deleteRecipe.graphql"
      - "src/graphql/mutations/login.graphql"
      - "src/graphql/mutations/logout.graphql"
      - "src/graphql/mutations/register.graphql"
      - "src/graphql/mutations/updateRecipe.graphql"
      - "src/graphql/queries/me.graphql"
      - "src/graphql/queries/recipe.graphql"
      - "src/graphql/queries/recipes.graphql"
    generates:
      src/generated/:
        plugins:
          - "typescript"
          - "typescript-operations"
          - "typescript-react-apollo"