【问题标题】:Graphql codegen configuration does not load documents with Glob ExpressionGraphql codegen 配置不使用 Glob 表达式加载文档
【发布时间】:2021-05-05 21:00:24
【问题描述】:

我的 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"

我不确定我到底做错了什么,更奇怪的是它曾经有效。我记得最近更新了我的部门。我看到并尝试了其他一些答案,例如 this onethis one 但无济于事:(

【问题讨论】:

    标签: typescript graphql apollo-client graphql-codegen


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 2020-05-29
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 2010-10-01
      • 2017-04-24
      • 2021-09-24
      相关资源
      最近更新 更多