Batching resolvers (data fetchers) #389
-
I really like the way that graphql-java-tools minimised boilerplate code and helped in getting started very quickly. Is there a documented way of achieving this? Or an example of how we can mix and use both graphql-java-tools and graphql-java together as per requirement? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
Are you using just graphql-java-tools or are you using it in combination with graphql-spring-boot-starter? There's an example on how to use data loaders in that repo, see: https://github.com/graphql-java-kickstart/graphql-spring-boot/tree/master/example-request-scoped-dataloader. |
Beta Was this translation helpful? Give feedback.
-
What you are talking about is not really batching (the batch strategy is deprecated) but data loading. That concept is unrelated to this library. Data loaders are usually accessible via |
Beta Was this translation helpful? Give feedback.
-
I had the same question while trying to get this setup with Micronaut. When you read the GraphQL Java docs they have a whole chapter on "batching" and make it sound very important that you implement a It looks like several others have had this question as well: #370 #291 #290 #151 #58. There's a lot of different parts to put together a working GraphQL server and it's a bit tricky to figure out what to use from each library. Perhaps we could add something to the docs? It looks like #58 has the best discussion of how this works |
Beta Was this translation helpful? Give feedback.
-
I just got this working after much struggling. The key point I was missing is that your |
Beta Was this translation helpful? Give feedback.
-
Now that I know how things work, https://github.com/graphql-java-kickstart/samples/tree/master/tools-hello-world doesn't seem very realistic. Everytime you get a character from the repository all their friends are returned too. But that's not really how you'd actually set things up if your app is backed by an RDBMS, which is the common case, because it'd be wasteful to fetch the friends if the GraphQL query doesn't request them. Instead, I think this would be the perfect place to demonstrate the usage of a |
Beta Was this translation helpful? Give feedback.
-
Glad you figured it out. I took me a while too as you can see in #58. The example you linked is correct. It might not be very realistic but it keeps things simple. Maybe we should add a separate example that demonstrates the use of data loader. There will always be a little bit of overfetching or underfetching when you back the GraphQL API with an RDBMS. |
Beta Was this translation helpful? Give feedback.
-
Hello @benmccann, regarding the example you're referring to: what do you mean by all their friends are returned too? Is that what's done in the methods in the e.g. for a single search (by id), retrieving the whole data?
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
I had the same question while trying to get this setup with Micronaut. When you read the GraphQL Java docs they have a whole chapter on "batching" and make it sound very important that you implement a
BatchLoader
for each type. When using graphql-java-tools it looks like we useGraphQLResolver
instead ofDataFetcher
and so there's this big open question in the docs of do we useBatchLoader
or does graphql-java-tools have its own version of that too? If we do useBatchLoader
how to we integrate it since some of the APIs are different (e.g. now we useSchemaParser
,SchemaParserBuilder
, etc. instead of the graphql-java versions)It looks like several others have had this question as well: #370