All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.javalin.plugin.graphql.GraphQLOptions.kt Maven / Gradle / Ivy

There is a newer version: 4.6.8
Show newest version
package io.javalin.plugin.graphql

import com.expediagroup.graphql.generator.TopLevelObject
import io.javalin.http.Context
import io.javalin.plugin.graphql.graphql.MutationGraphql
import io.javalin.plugin.graphql.graphql.QueryGraphql
import io.javalin.plugin.graphql.graphql.SubscriptionGraphql
import io.javalin.websocket.WsMessageContext


class GraphQLOptions(val path: String, val context: Any? = null) {
    var middleHandler: (Context) -> Unit = {  }
    var wsMiddleHandler: (WsMessageContext) -> Unit = {  }

    var queries: MutableList = mutableListOf()
    var mutations: MutableList = mutableListOf()
    var subscriptions: MutableList = mutableListOf()
    var packages: MutableList = mutableListOf("kotlin.Unit")

    fun register(vararg queries: QueryGraphql) = apply {
        this.queries.addAll(queries.map { TopLevelObject(it) })
    }

    fun register(vararg mutations: MutationGraphql) = apply {
        this.mutations.addAll(mutations.map { TopLevelObject(it) })
    }

    fun register(vararg subscriptions: SubscriptionGraphql) = apply {
        this.subscriptions.addAll(subscriptions.map { TopLevelObject(it) })
    }

    fun addPackage(`package`: String) = apply {
        this.packages.add(`package`)
    }

    fun setMiddleHandler(middleHandler: (Context) -> Unit) = apply {
        this.middleHandler = middleHandler
    }

    fun setWSMiddleHandler(wsMiddleHandler: (WsMessageContext) -> Unit) = apply {
        this.wsMiddleHandler = wsMiddleHandler
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy