Description
Describe the bug
If using DataFetchingInterceptor
field aliasing does not work, null
is always returned and it does not matter whether the aliased type was a scalar or a complex type.
Test Case
GraphQL schema
type Movie {
title: String
}
type Query {
movie: [Movie]
}
GraphQL request
query {
movie {
someAlias: title
}
}
Expected cypher query
since graphql-java
is handling aliasing the cypher should look like this:
MATCH (movie:Movie)
RETURN movie {
.title
} AS movie
instead it looks like this:
MATCH (movie:Movie)
RETURN movie {
someAlias: movie.title
} AS movie
Expected cypher params
Neo4j test data
Expected GraphQL response
{
"errors": [],
"data": {
"movie": [
{
"someAlias": "value representing the title"
}
]
},
"extensions": null,
"dataPresent": true
}
Additional context
If using Translator
this works fine because you get the cypher already with alias and you just run it and return the data as it was fetched by the cypher. If using DataFetchingInterceptor
the cypher still contains the alias so the fetched data looks god at first sight, but when returned from the DataFetchingInterceptor
graphql-java
does a mapping using the type definition to return with the information about aliasing used in the request query. So it completely ignores the someAlias
data in the result because it is not part of the type definition and instead it looks for title
which it expects in the result (since it is not there null
is returned) to later alias it with someAlias
by itself.
Note that aliasing on query level works fine because you just fetch the data from neo4j using the variable
(which can be an alias) but then return just the data from the DataFetchingInterceptor
without the variable
(without the alias) and aliasing is handled by graphql-java
again and this time correctly of course.
So while fixing that take into account that the Translator
approach might get broken.