Graphql 代码生成配置不使用 Glob 表达式加载文档

问题描述

我的 API 是用 TypeScript/Apollo 编写的,我能够在 http://localhost:4000/graphql 上运行查询/突变。 我的前端是 Next.js 和 Apollo 客户端。我使用 GraphQL Codegenerator 生成我需要的客户端代码

我正在使用:

"@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",

而我的 codegen.yml 文件

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

我在更改 API 解析器时运行的脚本是 "gen": "graphql-codegen --config codegen.yml"

如果我确实运行此代码,则会收到错误

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

但是如果将我的 codegen.yml 文件设置如下,它可以工作(并且我在其中一个组件中测试了一个查询,我可以访问数据):

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"

我不确定我到底做错了什么,更奇怪的是它曾经可以工作。我记得最近更新了我的 deps。我看到并尝试了其他一些答案,例如 herethis one 但无济于事:(

解决方法

经过反复试验,我最终从我的计算机中删除了该项目,从 repo、yarn install 和 yarn gen 中再次拉出它。它奏效了。去图!