如何配置 GraphQL Codegen 以输出可在 Node.js 中使用的客户端?

发布于 2025-01-14 23:06:43 字数 479 浏览 1 评论 0原文

我一直在使用 https://www.graphql-code-generator.com/ 来暂时生成 TypeScript 定义、Apollo Hooks 和 GraphQL 解析器。

但现在我希望它生成可以在 Node.js

节点上使用的 Apollo 客户端函数 示例:

const { contacts } = await queryContacts(search: 'Jack');

for (const contact of contacts) {
  // ...
}

如何配置 codegen.yaml 来生成 Apollo 客户端函数,类似于 queryContacts< /代码>?

I have been using https://www.graphql-code-generator.com/ to generate TypeScript definitions, Apollo Hooks and resolvers for GraphQL for a while.

But now I would like it to generate Apollo client functions that I could use on Node.js

Node Example:

const { contacts } = await queryContacts(search: 'Jack');

for (const contact of contacts) {
  // ...
}

How do I configure codegen.yaml to generate an Apollo client function, similar to queryContacts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舟遥客 2025-01-21 23:06:43

在插件中添加打字稿操作

例如:

overwrite: true
schema: "./apollo/schema.ts"
generates:
  lib/gen-types.ts:
    documents: ./queries/*.ts
    plugins:
      - typescript
      - typescript-operations
      - typescript-react-apollo
    config:
      reactApolloVersion: 3
      withHooks: true

add typescript-operation in plugins

for example:

overwrite: true
schema: "./apollo/schema.ts"
generates:
  lib/gen-types.ts:
    documents: ./queries/*.ts
    plugins:
      - typescript
      - typescript-operations
      - typescript-react-apollo
    config:
      reactApolloVersion: 3
      withHooks: true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文