Apollo 客户端:codegen 不会为输入创建类型
我是 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终使用了 graphql-codegen 它给我的不仅仅是
apollo cli< /代码> 可以。仅供参考,
apollo cli
现已弃用。I ended up using graphql-codegen which gives me more than what
apollo cli
can. And FYIapollo cli
is now deprecated.