-
Notifications
You must be signed in to change notification settings - Fork 155
Description
First, sorry for the long text. But I could explain it better that way. 😄
Describe the bug
As I understand, fields at root level (queries or mutations) are resolved by neo4j/graphql with independent resolvers. Each resolver generates a cypher query.
But I noticed that if a Neo4jGraphQLError is thrown in one of these "independent" resolvers, the resolution in the other resolvers sometimes doesn't work properly anymore. Depending on what is resolved first, results from successful resolvers may no longer appear in the response.
I made a detailed example to explain the issue:
Type definitions
type Movie {
name: String!
genres: [Genre!]! @relationship(type: "HAS_GENRE", direction: OUT)
}
type Genre {
name: String! @unique
}
To Reproduce
Steps to reproduce the behavior:
- Run a server with the following code... (Make sure to add a constraint!)
- Execute the following Mutation:
mutation {
createGenres(input: {name: "TestGenre1"}) {
genres {
name
}
}
createMovies(input: {name: "TestMovie1"}) {
movies {
name
}
}
}
Results ✔️:
As expected
{
"data": {
"createGenres": {
"genres": [
{
"name": "TestGenre1"
}
]
},
"createMovies": {
"movies": [
{
"name": "TestMovie1"
}
]
}
}
}
Nodes in database ✔️:
As expected
- Execute the same Mutation again:
mutation {
createGenres(input: {name: "TestGenre1"}) {
genres {
name
}
}
createMovies(input: {name: "TestMovie1"}) {
movies {
name
}
}
}
Result ❌:
createGenres didn't work. OK. But what about createMovies? This should resolve independently of createGenres.
{
"errors": [
{
"message": "Constraint validation failed",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createGenres"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR"
}
}
],
"data": null
}
Nodes in database ✔️:
As expected from the result, no nodes were created. OK
- Execute the same Mutation again, but in different order:
mutation {
createMovies(input: {name: "TestMovie1"}) {
movies {
name
}
}
createGenres(input: {name: "TestGenre1"}) {
genres {
name
}
}
}
Result ❌:
Same. What about createMovies?
{
"errors": [
{
"message": "Constraint validation failed",
"locations": [
{
"line": 7,
"column": 3
}
],
"path": [
"createGenres"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR"
}
}
],
"data": null
}
Nodes in database ❌:
But wait! Now a Movie node has been created, although the answer didn't indicate it.
Expected behavior
At the root level, queries and mutations should be resolved independently. An error in one resolver should not affect the result of the other resolver