@PublicApi public class SchemaTransformer extends java.lang.Object
GraphQLSchema
object by calling bac on a provided visitor.
To change a GraphQLSchemaElement
node in the schema you need
to return GraphQLTypeVisitor.changeNode(TraverserContext, GraphQLSchemaElement)
which instructs the schema transformer to change that element upon leaving that
visitor method.
public TraversalControl visitGraphQLObjectType(GraphQLObjectType objectType, TraverserContext<GraphQLSchemaElement> context) {
GraphQLObjectType newObjectType = mkSomeNewNode(objectType);
return changeNode(context, newObjectType);
}
To delete an element use GraphQLTypeVisitor.deleteNode(TraverserContext)
public TraversalControl visitGraphQLObjectType(GraphQLObjectType objectType, TraverserContext<GraphQLSchemaElement> context) {
return deleteNode(context, objectType);
}
To insert elements use either GraphQLTypeVisitor.insertAfter(TraverserContext, GraphQLSchemaElement)
or
GraphQLTypeVisitor.insertBefore(TraverserContext, GraphQLSchemaElement)
which will insert the new node before or after the current node being visited
public TraversalControl visitGraphQLObjectType(GraphQLObjectType objectType, TraverserContext<GraphQLSchemaElement> context) {
GraphQLObjectType newObjectType = mkSomeNewNode();
return insertAfter(context, newObjectType);
}
Constructor and Description |
---|
SchemaTransformer() |
Modifier and Type | Method and Description |
---|---|
GraphQLSchema |
transform(GraphQLSchema schema,
GraphQLTypeVisitor visitor) |
GraphQLSchema |
transform(GraphQLSchema schema,
GraphQLTypeVisitor visitor,
java.util.function.Consumer<GraphQLSchema.Builder> postTransformation) |
<T extends GraphQLSchemaElement> |
transform(T schemaElement,
GraphQLTypeVisitor visitor) |
static GraphQLSchema |
transformSchema(GraphQLSchema schema,
GraphQLTypeVisitor visitor)
Transforms a GraphQLSchema and returns a new GraphQLSchema object.
|
static GraphQLSchema |
transformSchema(GraphQLSchema schema,
GraphQLTypeVisitor visitor,
java.util.function.Consumer<GraphQLSchema.Builder> postTransformation)
Transforms a GraphQLSchema and returns a new GraphQLSchema object.
|
static <T extends GraphQLSchemaElement> |
transformSchema(T schemaElement,
GraphQLTypeVisitor visitor)
Transforms a
GraphQLSchemaElement and returns a new element. |
public static GraphQLSchema transformSchema(GraphQLSchema schema, GraphQLTypeVisitor visitor)
schema
- the schema to transformvisitor
- the visitor call backpublic static GraphQLSchema transformSchema(GraphQLSchema schema, GraphQLTypeVisitor visitor, java.util.function.Consumer<GraphQLSchema.Builder> postTransformation)
schema
- the schema to transformvisitor
- the visitor call backpostTransformation
- a callback that can be as a final step to the schemapublic static <T extends GraphQLSchemaElement> T transformSchema(T schemaElement, GraphQLTypeVisitor visitor)
GraphQLSchemaElement
and returns a new element.T
- for twoschemaElement
- the schema element to transformvisitor
- the visitor call backpublic GraphQLSchema transform(GraphQLSchema schema, GraphQLTypeVisitor visitor)
public GraphQLSchema transform(GraphQLSchema schema, GraphQLTypeVisitor visitor, java.util.function.Consumer<GraphQLSchema.Builder> postTransformation)
public <T extends GraphQLSchemaElement> T transform(T schemaElement, GraphQLTypeVisitor visitor)