微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法将枚举值传递给突变

如何解决无法将枚举值传递给突变

我有以下架构定义:

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,同样的问题

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。