问题描述
我有以下架构定义:
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,},});
GraphQL 错误:应为“CommunityType”类型的值,但收到:“company”
似乎 Apollo Client 以某种方式将枚举值 COMPANY
转换为小写。
我正在使用 apollo-client 2.6.8
。编辑:我升级到 apollo-client 3.3.6
,同样的问题
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)