graphql-query-complexity
graphql-query-complexity copied to clipboard
Weird error when running mutations with invalid inputs
Hey, I've encountered a bug when running mutations and providing an invalid input.
Given the following schema
type Query {
hello: String
}
input AddFavoriteFoodInput {
id: ID!
comment: String!
foodNames: [String!]!
}
type Mutation {
addFavoriteFood(input: AddFavoriteFoodInput!): Boolean!
}
if you run the mutation
mutation AddFavoriteFood($input: AddFavoriteFoodInput!) {
addFavoriteFood(input: $input)
}
with variables
{
"input": {
"id": "123",
"comment": "Hello",
"foodNames": [
"Pizza",
"Apple",
null,
"Pineapple"
]
}
}
the expected error message is:
"Variable \"$input\" got invalid value null at \"input.foodNames[2]\";
Expected non-nullable type \"String!\" not to be null."
However with GraphQL Complexity enabled, this turns into
"Argument \"input\" of required type \"AddFavoriteFoodInput!\" was provided the
variable \"$input\" which was not provided a runtime value."
Here's a repo reproducing the issue: https://github.com/adamors/graphql-complexity-bug
Hello @adamors, I'm getting the same error as well. have you found any workarounds? thank you.
@ahrbil not really, currently any code that calls the graphql complexity methods is wrapped in a try/catch and the error is discarded.
This library does not implement query and input validation to not duplicate the functionality and increase execution costs. So the error messages can vary. One option would be to validate the query and input arguments using the functions from the graphql-js library before running the complexity calculation.
~~I'm actually seeing this when valid input is given. Feels like a bug in the library itself.~~
Taking this back - any error is obscured by this cryptic error when using this library. In development it'd be nice to have the actual errors sent to the client.
This library does not implement query and input validation to not duplicate the functionality and increase execution costs. So the error messages can vary. One option would be to validate the query and input arguments using the functions from the
graphql-jslibrary before running the complexity calculation.
@ivome I don't understand your work-around - can you elaborate?
This should be fixed by the changes from #78