Apollo 客户端:codegen 不会为输入创建类型

发布于 2025-01-15 08:26:57 字数 1544 浏览 2 评论 0原文

我是 GraphQL 新手,目前正在我们的 TypeScript React 项目中使用 Apollo Client。我目前正在尝试使用 client:codegen 命令生成类型,但它不包括突变输入。这是目前我在 package.json 中的脚本

"codegen:auth-api": "apollo client:codegen --target typescript --includes=\"./src/graphql/auth-api/**/*.ts\" --outputFlat --endpoint=\"https://frontend-engineer-onboarding-api-thxaa.ondigitalocean.app/graphql\" \"src/types\"",

,它输出这个

import { SignUpInput } from "./globalTypes";

// ====================================================
// GraphQL mutation operation: SignUp
// ====================================================

export interface SignUp_signUp {
  __typename: "Authentication";
  token: string;
}

export interface SignUp {
  /**
   * ### Description
   * Sign up a user and get an access token if successful.
   * 
   * ### Error Codes
   * `BAD_USER_INPUT` - Email address already used.
   */
  signUp: SignUp_signUp;
}

export interface SignUpVariables {
  input: SignUpInput;
}

上面的问题是 globalTypes.ts 是空的,而它应该具有如下所示的内容

interface SignUpInput {
...
}

这是一个示例我的突变代码

export const SIGN_UP = gql`
  mutation SignUp($input: SignUpInput!) {
    signUp(input: $input) {
      token
    }
  }
`;

有什么我遗漏的吗?我也尝试过传递 --passthroughCustomScalars 但这只是删除了自定义标量。如果我在这里找不到任何答案,我深表歉意,并提前感谢您的帮助。

I am new to GraphQL and is currently using Apollo Client on our TypeScript React project. I am currently trying to generate types using client:codegen command and it is not including the Inputs on Mutations. This is currently the script I have in my package.json

"codegen:auth-api": "apollo client:codegen --target typescript --includes=\"./src/graphql/auth-api/**/*.ts\" --outputFlat --endpoint=\"https://frontend-engineer-onboarding-api-thxaa.ondigitalocean.app/graphql\" \"src/types\"",

That outputs this

import { SignUpInput } from "./globalTypes";

// ====================================================
// GraphQL mutation operation: SignUp
// ====================================================

export interface SignUp_signUp {
  __typename: "Authentication";
  token: string;
}

export interface SignUp {
  /**
   * ### Description
   * Sign up a user and get an access token if successful.
   * 
   * ### Error Codes
   * `BAD_USER_INPUT` - Email address already used.
   */
  signUp: SignUp_signUp;
}

export interface SignUpVariables {
  input: SignUpInput;
}

The problem above is that globalTypes.ts is empty when it should have something like below

interface SignUpInput {
...
}

This is a sample of my mutation code

export const SIGN_UP = gql`
  mutation SignUp($input: SignUpInput!) {
    signUp(input: $input) {
      token
    }
  }
`;

Is there something I am missing? I've also tried passing --passthroughCustomScalars but that just removes custom scalars. I apologize if I could not find any answer here on SO and Thanks in advance for your help.

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

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

发布评论

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

评论(1

恍梦境° 2025-01-22 08:26:58

我最终使用了 graphql-codegen 它给我的不仅仅是 apollo cli< /代码> 可以。仅供参考,apollo cli 现已弃用。

I ended up using graphql-codegen which gives me more than what apollo cli can. And FYI apollo cli is now deprecated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文