【问题标题】:Create a mutation which takes multiple values of an ENUM创建一个接受多个 ENUM 值的突变
【发布时间】:2017-08-10 21:53:05
【问题描述】:

我创建了一个模型,该模型具有一个字段,该字段采用ENUM 的多个值。如何编写允许我一次添加多个值的突变?

例如,我有一个注册突变:

export const signUp = gql`
  mutation signUp(
    $email: String!,
    $name: String!,
    $password: String!,
    $attended: [USER_ATTENDED!]!,
    $role: [USER_ROLE!]!,
  ) {
    createUser(
      authProvider: {
        email: {
          email: $email,
          password: $password,
        },
      },
      name: $name,
      attended: $attended,
      role: $role,
    ) {
      id,
      createdAt,
      name,
      email,
    }
  }
`;

我希望 $attended$role 接受多个值。

【问题讨论】:

  • 我不确定你的问题是什么。正如它所写的那样,它似乎会接受一组值。不是这样吗?

标签: graphql apollo-client graphcool


【解决方案1】:

您可以使用方括号传递多个值:[]。在您的情况下,GraphiQL 中的变量需要像这样:

{
  "email": "name@email.com",
  "name": "Name",
  "password": "secret",
  "attended": ["A", "B"],
  "role": ["ROLE_A", "ROLE_B"]
}

在 Apollo 中,这应该可以工作:

const variables = {
  email: "name@email.com",
  name": "Name",
  password: "secret",
  attended: ["A", "B"],
  role: ["ROLE_A", "ROLE_B"]
}

有关 GraphQL 变量的更多信息,请访问 herehere

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    • 2021-02-16
    • 2019-02-17
    • 2015-01-18
    • 2019-09-01
    相关资源
    最近更新 更多