Reputation: 335
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.
Upvotes: 1
Views: 1653
Reputation: 7808
You can pass multiple values by using brackets: []
. In your case, the variables in GraphiQL need to like like this:
{
"email": "[email protected]",
"name": "Name",
"password": "secret",
"attended": ["A", "B"],
"role": ["ROLE_A", "ROLE_B"]
}
In Apollo, this should work:
const variables = {
email: "[email protected]",
name": "Name",
password: "secret",
attended: ["A", "B"],
role: ["ROLE_A", "ROLE_B"]
}
More information about GraphQL variables is available here and here.
Upvotes: 4