Skip to content

Make coroutine scope configurable via context #350

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

Conversation

martinraison
Copy link
Contributor

@martinraison martinraison commented Jan 4, 2020

When using suspending resolvers, graphql-java-tools launches coroutines in the global scope, which makes it impossible to structure concurrency properly. More details on why using GlobalScope is not recommended: https://medium.com/@elizarov/the-reason-to-avoid-globalscope-835337445abc.

This PR makes the coroutine scope configurable. This is done by having the GraphQL context implement CoroutineScope. It is of course completely optional, GlobalScope will still be used by default.

Note: this is different from coroutineContextProvider in SchemaParserOptions, which does not override the scope, and does not allow having a different scope for each request. A concrete use-case for per-request scopes is to ensure all coroutines spawned by any given request are cancelled after at most 1 minute.

@oliemansm oliemansm merged commit b9d4b12 into graphql-java-kickstart:master Jan 15, 2020
@oliemansm oliemansm added this to the 5.7.2 milestone Jan 15, 2020
@oliemansm oliemansm modified the milestones: 5.7.2, 6.0.0 Feb 19, 2020
@aymanmoukhtar
Copy link

aymanmoukhtar commented Jun 4, 2020

I need some help please, probably it is my lack of Kotlin knowledge speaking.
In order to make use of this PR, should i implement my own GraphQLServletContext?
am using

com.graphql-java-kickstart:graphql-spring-boot-starter:7.0.1
com.graphql-java-kickstart:graphql-java-tools:6.0.2

So am basically not providing any configurations on my own, they're just picked up automatically, i can't see how to make use of this feature in such case, can i? or must i provide my own GraphQLServletContext implementation? and if so, how to do it? is there a way to just extend it?

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants