typescript - 无法将枚举值传递给突变
问题描述
我有以下架构定义:
enum CommunityType {
INTEREST
COMPANY
INDUSTRY
}
...
extend type Mutation {
createCommunity(name: String!, type: CommunityType): Community
}
以及以下突变:
mutation CreateCommunity($name: String!, $type: CommunityType) {
createCommunity(name: $name, type: $type) {
id
name
type
}
}
Apollo 也为我生成了正确的 TypeScript 类型:
export interface CreateCommunity_createCommunity {
__typename: "Community";
id: string | null;
name: string | null;
type: CommunityType | null;
}
export interface CreateCommunity {
createCommunity: CreateCommunity_createCommunity | null;
}
export interface CreateCommunityVariables {
name: string;
type?: CommunityType | null;
}
和全局类型:
/**
* CommunityType
*/
export enum CommunityType {
COMPANY = "COMPANY",
INDUSTRY = "INDUSTRY",
INTEREST = "INTEREST",
LOCATION = "LOCATION",
MINISTRY = "MINISTRY",
}
当我像这样使用突变时
const [create, {
loading,
error,
}] = useMutation<CreateCommunity, CreateCommunityVariables>(CREATE_COMMUNITY, {
variables: {
name: title,
type: CommunityType.COMPANY,
},
});
调用时出现此错误create
:
GraphQL 错误:应为“CommunityType”类型的值,但收到:“company”
似乎 Apollo Client 以某种方式将枚举值转换COMPANY
为小写。
我正在使用 apollo-client 2.6.8
。编辑:我升级到 apollo-client 3.3.6
,同样的问题
解决方案
推荐阅读
- postgresql - Docker golang gin postgres
- angular - 如何在 Angular 应用程序中将图像上传到图像到 imgur?
- c - C中OpenGL中的着色器问题
- git - Git stash 在 pre-receive 和 post-receive 钩子中没有按预期工作
- java - 再一次 =>“您的 SQL 语法有错误;请查看与您的 MariaDB 服务器相对应的手册...”
- c - 如何在循环中在同一个套接字上发送 send() 和 recv()?
- r - 为什么 sf_auth() 不适用于“部分环境沙盒”?
- python - /shop/process_payment/ 处的 FieldError 无法将关键字“id”解析为字段。选项有:地址、金额、电子邮件、items_json、姓名、order_id、电话
- r - 使用数据表左连接
- javascript - 为什么在 JavaScript 的 IF 语句中允许重新声明变量