Description
Motivation
My output types in the schema are the same as my input types except the latter ones don't have id
field. For conciseness reasons, I use the same underlying DTO with nullable id for both types. This works well in the main code flow because id
is set to null on input while it has some value on the output.
In the tests, though, I want to use my DTOs as input variables, e.g.
graphQlTester
.document(SOME_QUERY)
.variable("var", SomeDtoWithIdField)
.execute()
Now I obviously don't want the variable var
to contain the id
field because it's not defined in the input type corresponding to SomeDtoWithIdField
. I was thinking about how to drop the id
from the serialized var
and thought that the following code surely wouldn't work because "GraphQL does not use Jackson annotations to drive JSON serialization/deserialization".
class SomeDtoWithIdField {
@get:JsonIgnore
var id: Long? = null
}
But my colleague tried that anyway and to my surprise, it worked :-) That is, in my test case the id
is not serialized into var
while in the main flow the id
is serialized to the output type. My hypothesis is that while in the normal flow spring-grqphql uses some custom serializer, GraphQlTester
uses Jackson.
Questions
- Is this expected behavior? Shouldn't rather
GraphQlTester
use the same serializer as the main flow? - If both flows should indeed behave consistently, then how could I achieve my use case? Is it somehow possible to hook into the serialization process?
(This question can be read as a sort of reverse of #521)