We have large set of GraphQL queries and mutation for our Android app. Sometimes we make error where we make large set of changes to these queries/mutation.
Say, a mutation ends up defining a variable that is never actually used, that causes error shown below
GraphQLResponseErrors: GraphQL request for SomeQuery has errors: [Variable “$someVariable” is never used in operation
Is there a way to unit test the graphQL query/mutation specifically to catch the unused variable errors?
Hi!
There is no straightforward way to do this as a unit test, but you can make the presence of warnings be treated as an error. This will break your build as long as there are any such instances and help you pinpoint the erroneous operations. To do this, enable the failOnWarnings
option like so:
apollo {
// Your other options
// ...
failOnWarnings.set(true)
}
1 Like
Thanks for that suggestion.
In our project we are using version 3.7.5 and setting failOnWarnings.set(true) didn’t make a difference.
But bumping version to latest stable 3.8.2, setting failOnWarnings to true, produced the compile time error. This is awesome, thanks for your help!