I'm attempting to create a mutation that updates the value of an enum and also being able to query by that enum using schema language. Here is the enum type in question :
const Role = `
# Roles that grant users specific permissions.
enum Role {
# Users with access to admin-specific features.
ADMIN
# Users with access to contributor-specific features.
CONTRIBUTOR
}
`;
As well as the mutation:
const userMutations = `
# Finds a user by email and changes their role to either ADMIN or CONTRIBUTOR.
updateUserRole(
email: String!
role: Role!
): User
`;
This is what I get back when from either a query or mutation with a param with the Role type:
{
"errors": [
{
"message": "Argument \"role\" has invalid value \"ADMIN\".\nExpected \"Role\", found not an object.",
"locations": [
{
"line": 2,
"column": 25
}
]
}
]
}
It works perfectly fine for returning values from queries. If I manually inject a user with an invalid role it will error when I query it. I'm sure this will end up being something obvious. Not sure if it is a limitation of the schema language, as I've found working examples building the enum programmatically. Any help is much appreciated.
How are you specifying the value for the role argument? Note that if you write the value inline in the mutation query (instead of using a variable) then it must be written without quotes, e.g. mutation Foo { updateUserRole(role: ADMIN, ...) ..., as opposed to role: "ADMIN".
That was it! Thanks @josephsavona. Is that anywhere in the documentation?
I think the enum examples on graphql.org don't use quotes.
Most helpful comment
How are you specifying the value for the
roleargument? Note that if you write the value inline in the mutation query (instead of using a variable) then it must be written without quotes, e.g.mutation Foo { updateUserRole(role: ADMIN, ...) ..., as opposed torole: "ADMIN".