Return POJO instead of LinkedHashMap
See original GitHub issueDear all,
I’m trying to use graphql-java for loading a graph of in-memory java objects and doing some transformations on them (e.g. exporting to CSV).
When I use graphql.execute(ExecutionInput)
, it always provides a list of nested LinkedHashMap
s
However, I would prefer having results as POJOs.
I dig a little bit into the code, and found, that the results are aggregated in AbstractAsyncExecutionStrategy#handleResults
. So I decided to implement a custom strategy, which would build POJO directly.
However, I don’t see any way, how to know, which output class it should be. I could take it from the current ExecutionPath
(which is available in ExecutionStrategyParameters
), but handleResults
doesn’t have this parameter.
So, my questions are:
- Is there any way to get current ExecutionPath in
handlerResults
? - Is there any other way to produce POJO instead of LinkedHashMap?
PS thanks a lot for the wonderful library!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
I am not sure that returning POJOs is the right thing to do.
graphql is a system where the consumer indicates what data they want. They may ask for 6 fields or 2. They may ask for it down 3 levels or 1.
The map approach we use (where ExecutionResult is a temporary holder and converted into a map as we descend and return up from the query level is very deliberate.
It allows
To become a map like
Maybe you ask for tricks in a query or maybe you dont. The idea of this being POJOs as we execute the engine is not sensible in my opinion.
Let’s say you had POJOs hypothetically. What would you do with them? Throw them at Jackson ObjectMapper and send them over the wire as JSON? A Map is just as good for that, in some ways better (no reflection needed).
You say
Can you outline your thoughts on why POJOs would help you build better graphql based software?
Hi, it seems my change was reverted: https://github.com/graphql-java/graphql-java/commit/1bd60a39e984368fb7c724360e8f072ba2c84c4f
Can we revert it please?
CC @dugenkui03