1

I've created a model that has a field which takes multiple values of an ENUM. How can I write a mutation which will allow me to add multiple values at once?

For example, I have a sign up mutation:

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,
    }
  }
`;

I would expect $attended and $role to accept multiple values.

vinspee
  • 335
  • 1
  • 8
  • I'm not sure what your question is. As it's written it seems like it would accept an array of values. Is that not the case? – helfer Mar 20 '17 at 02:34

1 Answers1

4

You can pass multiple values by using brackets: []. In your case, the variables in GraphiQL need to like like this:

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

In Apollo, this should work:

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

More information about GraphQL variables is available here and here.

marktani
  • 7,578
  • 6
  • 37
  • 60