GitHunt
DA

darkxanter/graphql-kotlin-ktor

Ktor plugin for graphql-kotlin.

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 = "johndoe@example.com",
                firstName = "John",
                lastName = "Doe",
            )
            mapOf(
                "AuthorizedContext" to AuthorizedContext(loggedInUser)
            )
        }
    }
}

Languages

Kotlin83.7%TypeScript11.3%Vue2.9%HTML1.3%CSS0.8%

Contributors

MIT License
Created June 19, 2022
Updated December 24, 2023