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

graphql.nadel.schema.SchemaTransformationHook.kt Maven / Gradle / Ivy

Go to download

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

There is a newer version: 2024-11-20T03-31-21-302962b7
Show newest version
package graphql.nadel.schema

import graphql.nadel.Service
import graphql.schema.GraphQLSchema

/**
 * High level representation of a transformation for an overall (not underlying) schema. Warning: the schema resulting
 * from the transformation is not validated by Nadel, so may produce unpredictable results if incorrect.
 *
 *
 * Example usage, to delete a field:
 * `
 * SchemaTransformation transformation = originalSchema -> {
 * @Override
 * GraphQLSchema apply(GraphQLSchema originalSchema) {
 * return SchemaTransformer.transformSchema(originalSchema, new GraphQLTypeVisitorStub() {
 * @Override
 * TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition node, TraverserContext context) {
 * if (node.getName() == "secretField") {
 * return TreeTransformerUtil.deleteNode(node);
 * }
 *
 * return TraversalControl.CONTINUE;
 * }
 * }
 * }
 * }
` *
 *
 * @see graphql.schema.SchemaTransformer
 *
 * @see graphql.schema.GraphQLTypeVisitorStub
 */
fun interface SchemaTransformationHook {
    /**
     * Apply a transformation to a schema object, returning the new schema.
     *
     * @param originalSchema input schema
     * @param services       the list of Nadel services
     *
     * @return transformed schema
     */
    fun apply(originalSchema: GraphQLSchema, services: List): GraphQLSchema

    companion object {
        val Identity = SchemaTransformationHook { originalSchema, _ -> originalSchema }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy