graphql - 直接通过 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 可以自动将所有已知字段放在那里。
解决方案
Codegen 没有这样做。主要是因为它无法猜测哪些字段、嵌套级别和参数。GraphQL 就是关于指定您的选择集并优化您的数据获取。如果您只想拉取所有内容,则可以编写自己的工具来根据需要构建选择集。或者,好吧,使用不同的 API 框架......
推荐阅读
- python - 如何从for循环中的类中获取实例名称
- python-3.x - Python 3 错误:ExternalError:RangeError:main.py 中的第 48 行超出了最大调用堆栈大小
- sql - 使用子查询执行 IIF 条件的最佳方法
- sql - 在两个表中生成相交行的查询
- python - 使用列表列表过滤列表列表
- r - 将 clusterOptions 与 addPolygons 或 addRasterImage 一起使用时未呈现传单 addMarkers
- c++ - “gtk_text_buffer_get_bounds”函数导致 SEGFAULT
- angular - 无法绑定到“ngIF”,因为它不是“ion-item”的已知属性
- vue.js - 如何在 axios.get() 中添加前缀 sparql
- ms-access - 在将 MS Access 中的控件发送到表中进行验证之前,是否存在更改控件值的事件