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

Allow wrapping all resolvers #219

Open
Martmists-GH opened this issue Jul 25, 2023 · 0 comments
Open

Allow wrapping all resolvers #219

Martmists-GH opened this issue Jul 25, 2023 · 0 comments

Comments

@Martmists-GH
Copy link

Martmists-GH commented Jul 25, 2023

In my use case, KGraphQL is resolving fields lazily using Exposed. However, even when installing a hook in the pipeline at Setup which wraps the call in a newSuspendedTransaction block, it seems the dispatcher-based design of KGraphQL ignores it. Similarly, I tried creating a custom dispatcher:

        coroutineDispatcher = object : CoroutineDispatcher() {
            override fun dispatch(context: CoroutineContext, block: Runnable) {
                Dispatchers.Default.dispatch(context) {
                    transaction(database) {
                        block.run()
                    }
                }
            }
        }

however this still raises the "No transaction in context" error.

Alternatively, would it be possible to provide a RequestExecutor which does not dispatch each field and instead iterates over each, all on the same coroutine context in which the call happens so setups like this could work?

object ExposedGraphQLPatch : Plugin<Application, Unit, Unit> {
    override val key = AttributeKey<Unit>("ExposedGraphQLPatch")

    override fun install(pipeline: Application, configure: Unit.() -> Unit) {
        pipeline.intercept(ApplicationCallPipeline.Setup) {
            if (
                call.request.httpMethod == HttpMethod.Post &&
                call.request.path() == "/graphql"
            ) {
                newSuspendedTransaction(Dispatchers.IO, Globals.database) {
                    proceed()
                }
            } else {
                proceed()
            }
        }
    }
}
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

1 participant