Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use @GraphQLContext for batching without @Batched #48

Closed
oleg-savko opened this issue Dec 8, 2017 · 2 comments
Closed

Use @GraphQLContext for batching without @Batched #48

oleg-savko opened this issue Dec 8, 2017 · 2 comments

Comments

@oleg-savko
Copy link

oleg-savko commented Dec 8, 2017

Is exists way to use @GraphQLContext for batching not via @Batched annotation?
For example for batching via https://github.com/graphql-java/java-dataloader?

Or only one way to explicitly connect it via model?

@oleg-savko oleg-savko changed the title Use @GraphQLContext without @Batched Use @GraphQLContext for batching without @Batched Dec 8, 2017
@kaqqao
Copy link
Member

kaqqao commented Dec 8, 2017

@Batched in SPQR provides the same semantics as that annotation already provides in graphql-java (note that it belongs to a graphql-java package, not SPQR). It provides a simple batching model that maps well to SQL (and some other) backends. It works with BatchedExecutionStrategy only.

Dataloader offers a very different strategy. To use dataloader, you must write the batch loader functions yourself and then change your logic to fetch data through the dataloader instead of directly. Unlike the previous model, it's not down to the execution strategy, but down to how you write your datafetchers. SPQR doesn't know what your methods do, so you need to change your own code to use the dataloader.

You might want to create a DataLoaderRegistry per request, and stick into the global context. This way you can easily inject it into your resolver methods via @GraphQLRootContext. Or, since you're using Spring, make DataLoaderRegistry a request scoped bean that you inject into your service classes.
You must also make sure to register a DataLoaderDispatcherInstrumentation to dispatch the batch jobs. But this is all completely external to SPQR.

Keep in mind, SPQR only really deals with assembling the schema and wiring your methods as datafetchers. Actually executing the queries you do using graphql-java directly.

@kaqqao
Copy link
Member

kaqqao commented Dec 10, 2017

You can see a simple example of using @Batched in BatchingTest

@kaqqao kaqqao closed this as completed Dec 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants