I'm working through a GraphQL Node/Prisma server tutorial and encountered an error due to something wrong in my code. I've solved the error but I want to understand the error message, in particular, what does locations
refers to? That is, I have a location
of line 2, column 3, but line 2, column 3 of what? The relevant method in my code (signup
, in this case)? Of my mutation?
// error message
{
"data": {
"signup": null
},
"errors": [
{
"message": "secretOrPrivateKey must have a value",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"signup"
]
}
]
}
Just like path
, locations
refers to where inside your GraphQL document the error occurred. You can see this for yourself using something like the SWAPI GraphQL endpoint. We can trigger a validation error by requesting a field that doesn't exist:
{
allFilmz
}
The resulting error has this locations
array:
[
{
"line": 2,
"column": 3
}
]
That's because the offending field is on line 2, starting with column 3. If we instead send:
{allFilmz}
we get:
[
{
"line": 1,
"column": 2
}
]
Generally, the path
of the error will be more informative than the locations
, but the path
won't exist when there are syntax errors in your document -- in those cases, the locations
are the only thing you can use to track down where your syntax error occurred.
Word of caution if using GraphQL Playground -- unlike GraphiQL, Playground will strip out comments and format your request before sending it, so the locations
may not match what you see in the Playground UI.