Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

darkxanter/graphql-kotlin-ktor

Repository files navigation

GraphQL Kotlin Ktor Plugin

Continuous Integration Maven Central

Ktor plugin for graphql-kotlin.

Also provides subscriptions implementation for protocols graphql-ws and graphql-transport-ws.

📦 Modules

Usage

dependencies {
    implementation("io.github.darkxanter.graphql", "graphql-kotlin-ktor-plugin", "<last-version>")
}
fun Application.configureGraphQLModule() {
    install(ContentNegotiation) {
        jackson()
    }
    install(CallLogging)
    install(WebSockets)
    install(GraphQLKotlin) {
        queries = listOf(
            HelloQueryService(),
        )
        subscriptions = listOf(
            SimpleSubscription()
        )

        schemaGeneratorConfig {
            supportedPackages = listOf("example.graphql")
        }

        generateContextMap { request ->
            val loggedInUser = User(
                email = "[email protected]",
                firstName = "John",
                lastName = "Doe",
            )
            mapOf(
                "AuthorizedContext" to AuthorizedContext(loggedInUser)
            )
        }
    }
}