graphql-spring-boot
graphql-spring-boot copied to clipboard
Exception handlers not called when exception is thrown when parsing variables
Describe the bug When using request variables in GraphQL, the behaviour is really different than without variables. My model has a query using variables, and when passing null in a non-nullable field, my custom exception handler is not called. Even worse, the backend actually returns 500, instead of the normal 200.
I haven't yet found a way to handle this error correctly.
To Reproduce
This is a minimal example:
# schema.graphqls
extend type Query {
groups(filters: GroupFilters): [Group!]!
}
input GroupFilters {
ids: [String!] # Notice the non-nullable string array element
}
type Group {
id: String!
name: String!
}
Calling the model (using the playground) with the following query
# Query
query GetEntity($filters: GroupFilters) {
groups(filters: $filters) {
id,
name
}
}
and the following variables
{"filters": {"ids": [null]}}
End up in a 500, and my custom exception handler not being called.
Expected behavior The same request, but not using any variables (so passing the filters directly) returns the following response
{
"errors": [
{
"message": "Validation error of type WrongType: argument 'filters.ids[0]' with value 'NullValue{}' must not be null @ 'groups'",
"locations": []
}
],
"extensions": {},
"data": null
}
Screenshots (My actual model is a bit more complex, but here's what I have) Using filters directly: it works
*Using variables: returns 500