graphql.nadel.enginekt.blueprint.IntrospectionService.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nadel-engine-nextgen Show documentation
Show all versions of nadel-engine-nextgen Show documentation
Nadel is a Java library that combines multiple GrahpQL services together into one API.
The newest version!
package graphql.nadel.enginekt.blueprint
import graphql.ExecutionInput
import graphql.GraphQL
import graphql.GraphqlErrorHelper.toSpecification
import graphql.language.AstPrinter
import graphql.nadel.NadelDefinitionRegistry
import graphql.nadel.Service
import graphql.nadel.ServiceExecution
import graphql.nadel.ServiceExecutionParameters
import graphql.nadel.ServiceExecutionResult
import graphql.schema.GraphQLSchema
import java.util.concurrent.CompletableFuture
internal class IntrospectionService constructor(
schema: GraphQLSchema,
introspectionRunnerFactory: NadelIntrospectionRunnerFactory,
) : Service(name, schema, introspectionRunnerFactory.make(schema), NadelDefinitionRegistry()) {
companion object {
const val name = "__introspection"
}
}
fun interface NadelIntrospectionRunnerFactory {
fun make(schema: GraphQLSchema): ServiceExecution
}
open class NadelDefaultIntrospectionRunner(schema: GraphQLSchema) : ServiceExecution {
private val graphQL = GraphQL.newGraphQL(schema).build()
override fun execute(serviceExecutionParameters: ServiceExecutionParameters): CompletableFuture {
return graphQL
.executeAsync(
ExecutionInput.newExecutionInput()
.query(AstPrinter.printAstCompact(serviceExecutionParameters.query))
.build()
)
.thenApply {
ServiceExecutionResult(
data = it.getData(),
errors = it.errors.mapTo(ArrayList(), ::toSpecification),
)
}
}
}