Skip to content

Utility to easily add a GraphQL endpoint to a Ktor project

License

Notifications You must be signed in to change notification settings

roschlau/ktor-graphql

Repository files navigation

ktor-graphql

Usage

To set up an endpoint at the default route (your.domain/graphql) with just a query resolver and without a custom GraphQL context:

fun Application.main() {
    install(Routing) {
        graphQL(
            "path/to/schema.graphqls",
            MyQueryResolver()
        )
    }
}

Setting up an endpoint at your.domain/subroute/my-custom-endpoint with a custom GraphQL context and multiple resolvers:

fun Application.main() {
    install(Routing) {
        route("subroute") {
            graphQL(
                "my-custom-endpoint",
                "path/to/schema.graphqls",
                ::MyContext,
                Query(),
                Mutation(),
                AnotherResolver()
            )
            graphiQL()
        }
    }
}

data class MyContext(val call: ApplicationCall)

About

Utility to easily add a GraphQL endpoint to a Ktor project

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages