How to use batch loaders in SPQR
See original GitHub issueHi! My question is connected with solving N+1 problem. I have a query:
@GraphQLQuery public List<Contact> contactList(@GraphQLContext User user, @GraphQLArgument(name = "offset", defaultValue = "0") int offset, @GraphQLArgument(name = "limit", defaultValue = "50") int limit) { return ....<some database logic> }
and it’s ok if i just want to retrieve one user, cause it costs me only 2 queries. But when I want to retrieve lets say 100 Users it becomes harder to compute. I found GraphQL DataLoader that potentially is able to solve the issue, but can’t make it work. I was tring to base my implementation on this but it didn’t work.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
Just for reference if someone finds this issue by googling 😃 This solution works: https://github.com/graphql-java-kickstart/graphql-spring-boot/tree/master/example-request-scoped-dataloader
no need for CustomGraphQLContextBuilder, just enough the following (with graphql-spqr-spring-boot-starter):
In case no starter used, see https://github.com/graphql-java/graphql-java/issues/1254
The only thing you have to use:
for getting fetching environment.
The latest graphql-java has a better organization.
DataLoaderRegistry
now goes intoExecutionInput
andDataLoaderDispatcherInstrumentation
is always registered. Also,DataFetchingEnvironment
gives access to ``DataLoaderRegistry` directly.