【问题标题】:Apollo client:codegen does not create types for inputsApollo 客户端:codegen 不会为输入创建类型
【发布时间】:2022-07-10 20:59:28
【问题描述】:

我是 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,但这只是删除了自定义标量。如果我在 SO 上找不到任何答案,我深表歉意,并提前感谢您的帮助。

【问题讨论】:

    标签: typescript graphql apollo-client codegen


    【解决方案1】:

    我最终使用了graphql-codegen,它给了我比apollo cli 更多的东西。仅供参考 apollo cli 现已弃用。

    【讨论】:

      猜你喜欢
      • 2019-11-16
      • 2018-01-02
      • 2017-09-27
      • 2021-04-02
      • 2020-05-15
      • 2020-01-19
      • 2021-01-13
      • 2020-08-29
      • 2022-11-04
      相关资源
      最近更新 更多