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

graphql.nadel.enginekt.NadelExecutionContext.kt Maven / Gradle / Ivy

Go to download

Nadel is a Java library that combines multiple GrahpQL services together into one API.

The newest version!
package graphql.nadel.enginekt

import graphql.ExecutionInput
import graphql.PublicApi
import graphql.nadel.NadelExecutionHints
import graphql.nadel.Service
import graphql.nadel.hooks.CreateServiceContextParams
import graphql.nadel.hooks.ServiceExecutionHooks
import graphql.normalized.ExecutableNormalizedOperation
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ConcurrentHashMap

@PublicApi
data class NadelExecutionContext(
    val executionInput: ExecutionInput,
    val query: ExecutableNormalizedOperation,
    val hooks: ServiceExecutionHooks,
    val hints: NadelExecutionHints,
) {
    private val serviceContexts = ConcurrentHashMap>()

    val userContext: Any?
        get() {
            return executionInput.context
        }

    /**
     * Get the service context for a given service
     */
    fun getContextForService(service: Service): CompletableFuture {
        return serviceContexts.getOrPut(service.name) {
            hooks.createServiceContext(
                CreateServiceContextParams(service)
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy