These are chat archives for graphql-java/graphql-java

24th
Jan 2018
Marcel Overdijk
@marceloverdijk
Jan 24 06:41
Thx @bbakerman @jweaver-personal Sure it’s about combining data. But there is always an entry point via the root Query like a method for retrieving persons.
Maybe my name PersonResource is not good but it contained all kind of reference data like a homeplanet of which data can be returned as well.
In my test setup I use a relational JPA layer as the storage model and convert them to the graph, with additional queries if needed.
How did you implement this in your apps? What kind of objects are you returning from your root Query methods in the Java code?
Jonathan Weaver
@jweaver-personal
Jan 24 06:46
You can map data fetchers to entire objects, but also to individual fields.. so it depends. If you want to return a JPA annotated pojo that should work fine at the type level.
Jonathan Weaver
@jweaver-personal
Jan 24 07:01
The project I'm working on now aggregates information among a bunch of rest services that have specific rate limits so I took a event bus approach in which each fetcher sends a request to an event bus while returning a promise, as soon as the result appears on the event bus the promise resolves and when all of them resolve the query returns. So each data fetcher is just a message handler on the event bus and will return either a POJO or a specific field depending. Allowed me to decouple the REST interfaces to basically rate limited queues that are independent of graphql as an endpoint (there are other interfaces).
Marcel Overdijk
@marceloverdijk
Jan 24 07:39
So basically you have a specific model for the GraphQL layer (DTO's, POJO's) that are populated based on data from other services?
Jonathan Weaver
@jweaver-personal
Jan 24 21:14
Again it's the datafetchers that are doing the work. And they can return an object where getters are called for fields, or it can return a specific field. There is nothing preventing your returned object from doing a live DB query and just wrapping a jdbc result with getters for columns.
Or returning a proxy pattern object that just delegates to your live application domain objects.
Brad Baker
@bbakerman
Jan 24 22:08
@marceloverdijk - the idea of putting a graphql endpoint over top of a bunch of existing REST apis and presenting a unified view of them is a very common graphql pattern. The GitHub graphql API for example does this
that is most of it has peer REST APIs that you would otherwise have to call individually