首页 > 解决方案 > 直接通过 apollo-codegen 执行操作,无需命名

问题描述

我正在使用带有 apollo 的 graphql-codegen 从打字稿中使用 graphql api。现在我必须以 1:1 的比例准确地复制很多 graphql 操作才能生成一些代码。例子:

mutation CreateAccount($name: String!, $email: String!, $password: String!) {
  signUp(name: $name, email: $email, password: $password, initialAdminAccount: $initialAdminAccount) {
    ...UserProfile
  }
}

那么是否有可能以某种方式signUp直接调用而不是将其包装在自定义突变中?我知道 graphql 要求我指定我想要的字段作为回报,但 codegen 可以自动将所有已知字段放在那里。

标签: graphqlapollographql-codegen

解决方案


Codegen 没有这样做。主要是因为它无法猜测哪些字段、嵌套级别和参数。GraphQL 就是关于指定您的选择集并优化您的数据获取。如果您只想拉取所有内容,则可以编写自己的工具来根据需要构建选择集。或者,好吧,使用不同的 API 框架......


推荐阅读