【问题标题】:GraphQL Code Generator - Graphql Document Validation FailedGraphQL 代码生成器 - Graphql 文档验证失败
【发布时间】:2021-10-12 23:41:18
【问题描述】:

我在运行时不断收到错误消息 yarn run graphql-codegen --config codegen.yml

错误提示

Found 1 error

  ✖ src/generated/graphql.tsx
    AggregateError: GraphQL Document Validation failed with 1 errors
        at Object.checkValidationErrors (/home/tsatsralt/code/st/workspade/web/node_modules/@graphql-tools/utils/index.js:960:1
5)
        at Object.codegen (/home/tsatsralt/code/st/workspade/web/node_modules/@graphql-codegen/core/index.cjs.js:102:15)
        at async process (/home/tsatsralt/code/st/workspade/web/node_modules/@graphql-codegen/cli/bin.js:992:56)
        at async Promise.all (index 0)
        at async /home/tsatsralt/code/st/workspade/web/node_modules/@graphql-codegen/cli/bin.js:999:37
        at async Task.task (/home/tsatsralt/code/st/workspade/web/node_modules/@graphql-codegen/cli/bin.js:778:17)

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

src/graphql/mutations/login.graphql

mutation Login($loginPassword: String!, $loginEmail: String!) {
  login(password: $loginPassword, email: $loginEmail) {
    errors {
      field
      message
    }
    user {
      ...RegularUser
    }
  }
}

用户解析器

@Resolver(User)
export class UserResolver {
  @Mutation(() => UserResponse)
  async login(
    @Arg("email") email: string,
    @Arg("password") password: string,
    @Ctx() { req }: Context
  ): Promise<UserResponse> { logic }

我完成了 ben awad 的 14 小时全栈 tutorial 并决定做一个类似的项目。但我遇到了这个问题。在网上找不到有用的东西,所以我决定在这里问。

我也有所有需要的依赖项

【问题讨论】:

    标签: typescript graphql graphql-codegen


    【解决方案1】:

    嗯,这个问题实际上很愚蠢。让我解释一下我的错误:

    使用 graphql-codegen 调试提示:

    codegen 并没有真正告诉您究竟是什么导致了错误。试试看
    console.error(error) 发生错误的地方。就我而言,我把它放在

    /home/tsatsralt/code/st/workspade/web/node_modules/@graphql-tools/utils/index.js
    

    这个错误几乎告诉我出了什么问题。我得到的错误是

     Variable "$input" of type "RegisterInput" used in position expecting type "RegisterInput!".
    

    我使用了一个名为 RegisterInput 的片段,但忘记在 register.graphql 文件中添加感叹号。

    希望我的错误也能帮助到你。

    【讨论】:

      猜你喜欢
      • 2019-06-06
      • 2020-10-16
      • 2018-07-24
      • 2023-03-30
      • 2019-08-26
      • 2018-10-17
      • 2019-12-22
      • 2020-05-03
      • 2021-11-03
      相关资源
      最近更新 更多