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
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 DataFetchingInterceptorgraphql-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.
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
GraphQL request
Expected cypher query
since
graphql-java
is handling aliasing the cypher should look like this:instead it looks like this:
Expected cypher params
Neo4j test data
Expected GraphQL response
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 usingDataFetchingInterceptor
the cypher still contains the alias so the fetched data looks god at first sight, but when returned from theDataFetchingInterceptor
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 thesomeAlias
data in the result because it is not part of the type definition and instead it looks fortitle
which it expects in the result (since it is not therenull
is returned) to later alias it withsomeAlias
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 theDataFetchingInterceptor
without thevariable
(without the alias) and aliasing is handled bygraphql-java
again and this time correctly of course.So while fixing that take into account that the
Translator
approach might get broken.