aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
298 stars 58 forks source link

Idea: Alternative design for integrating with ktor #190

Open LSafer opened 2 years ago

LSafer commented 2 years ago

I believe graphql doesn't need a plugin. Instead, it needs a routing extension just like the get and post extensions.

For example:

fun Route.configureGraphql() {
    route("/graphql") {
        graphqlPlayground()
        graphql {
            wrapErrors = true

            schema {
                firstSchema()
                secondSchema()
                thierdSchema()

                firstRootSchema()
                secondRootSchema()
                thierdRootSchema()
            }
        }
    }
}

This way we don't need the wrapWith: {...} and endpoint: String and playground: Boolean arguments in the configuration object. And gives us more flexibility and control over handling execution exceptions.


I made a library/utility implementing this design

https://github.com/lsafer/kgraphql-ktor

In this library I implemented the described design. Additionally, I fixed serialization issues and error handling.