Graphql codegen configuration does not load documents with Glob Expression

Graphql codegen configuration does not load documents with Glob Expression


0

My API is written with TypeScript/Apollo and I am able to run queries/mutations on https://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: "https://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: "https://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 🙁

3 Answers
3


2

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 https://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: "https://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: "https://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"


0

After some trial and error, I ended up deleting the project from my computer, pulling it again from the repo, yarn install and yarn gen. And it worked. Go figure!


0

I replaced documents: "src/graphql/**/*.graphql" by

documents: "src/graphql/**/*.{gql,graphql}"

The path of my schema was : src/graphql/Quries/GetCustomers.query.gql

I’m using :

"@apollo/client": "^3.7.2",
"@graphql-codegen/cli": "^2.16.1",
"@graphql-codegen/typescript": "2.8.5",
"@graphql-codegen/typescript-operations": "^2.5.10",
"@graphql-codegen/typescript-react-apollo": "^3.3.7",



Leave a Reply

Your email address will not be published. Required fields are marked *