Package graphql.schema
Class SchemaTransformer
java.lang.Object
graphql.schema.SchemaTransformer
Transforms a
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);
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
private static class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate NodeZipper
<GraphQLSchemaElement> moveUp
(GraphQLSchemaElement parent, Map<NodeZipper<GraphQLSchemaElement>, Breadcrumb<GraphQLSchemaElement>> sameParentsZipper) private void
replaceTypeReferences
(SchemaTransformer.DummyRoot dummyRoot, GraphQLSchema schema, GraphQLCodeRegistry.Builder codeRegistry, Map<String, GraphQLNamedType> changedTypes) transform
(GraphQLSchema schema, GraphQLTypeVisitor visitor) transform
(GraphQLSchema schema, GraphQLTypeVisitor visitor, Consumer<GraphQLSchema.Builder> postTransformation) <T extends GraphQLSchemaElement>
Ttransform
(T schemaElement, GraphQLTypeVisitor visitor) private Object
transformImpl
(GraphQLSchema schema, GraphQLSchemaElement schemaElement, GraphQLTypeVisitor visitor, Consumer<GraphQLSchema.Builder> postTransformation) static GraphQLSchema
transformSchema
(GraphQLSchema schema, GraphQLTypeVisitor visitor) Transforms a GraphQLSchema and returns a new GraphQLSchema object.static GraphQLSchema
transformSchema
(GraphQLSchema schema, GraphQLTypeVisitor visitor, Consumer<GraphQLSchema.Builder> postTransformation) Transforms a GraphQLSchema and returns a new GraphQLSchema object.static <T extends GraphQLSchemaElement>
TtransformSchema
(T schemaElement, GraphQLTypeVisitor visitor) Transforms aGraphQLSchemaElement
and returns a new element.private boolean
traverseAndTransform
(SchemaTransformer.DummyRoot dummyRoot, Map<String, GraphQLNamedType> changedTypes, Map<String, GraphQLTypeReference> typeReferences, GraphQLTypeVisitor visitor, GraphQLCodeRegistry.Builder codeRegistry, GraphQLSchema schema) zipperWithSameParent
(GraphQLSchemaElement parent, SchemaTransformer.RelevantZippersAndBreadcrumbs relevantZippers, boolean cleanup) private boolean
zipUpToDummyRoot
(List<NodeZipper<GraphQLSchemaElement>> zippers, List<List<GraphQLSchemaElement>> stronglyConnectedTopologicallySorted, Map<NodeZipper<GraphQLSchemaElement>, List<List<Breadcrumb<GraphQLSchemaElement>>>> breadcrumbsByZipper, Map<GraphQLSchemaElement, NodeZipper<GraphQLSchemaElement>> nodeToZipper)
-
Constructor Details
-
SchemaTransformer
public SchemaTransformer()
-
-
Method Details
-
transformSchema
Transforms a GraphQLSchema and returns a new GraphQLSchema object.- Parameters:
schema
- the schema to transformvisitor
- the visitor call back- Returns:
- a new GraphQLSchema instance.
-
transformSchema
public static GraphQLSchema transformSchema(GraphQLSchema schema, GraphQLTypeVisitor visitor, Consumer<GraphQLSchema.Builder> postTransformation) Transforms a GraphQLSchema and returns a new GraphQLSchema object.- Parameters:
schema
- the schema to transformvisitor
- the visitor call backpostTransformation
- a callback that can be as a final step to the schema- Returns:
- a new GraphQLSchema instance.
-
transformSchema
public static <T extends GraphQLSchemaElement> T transformSchema(T schemaElement, GraphQLTypeVisitor visitor) Transforms aGraphQLSchemaElement
and returns a new element.- Type Parameters:
T
- for two- Parameters:
schemaElement
- the schema element to transformvisitor
- the visitor call back- Returns:
- a new GraphQLSchemaElement instance.
-
transform
-
transform
public GraphQLSchema transform(GraphQLSchema schema, GraphQLTypeVisitor visitor, Consumer<GraphQLSchema.Builder> postTransformation) -
transform
-
transformImpl
private Object transformImpl(GraphQLSchema schema, GraphQLSchemaElement schemaElement, GraphQLTypeVisitor visitor, Consumer<GraphQLSchema.Builder> postTransformation) -
replaceTypeReferences
private void replaceTypeReferences(SchemaTransformer.DummyRoot dummyRoot, GraphQLSchema schema, GraphQLCodeRegistry.Builder codeRegistry, Map<String, GraphQLNamedType> changedTypes) -
traverseAndTransform
private boolean traverseAndTransform(SchemaTransformer.DummyRoot dummyRoot, Map<String, GraphQLNamedType> changedTypes, Map<String, GraphQLTypeReference> typeReferences, GraphQLTypeVisitor visitor, GraphQLCodeRegistry.Builder codeRegistry, GraphQLSchema schema) -
zipUpToDummyRoot
private boolean zipUpToDummyRoot(List<NodeZipper<GraphQLSchemaElement>> zippers, List<List<GraphQLSchemaElement>> stronglyConnectedTopologicallySorted, Map<NodeZipper<GraphQLSchemaElement>, List<List<Breadcrumb<GraphQLSchemaElement>>>> breadcrumbsByZipper, Map<GraphQLSchemaElement, NodeZipper<GraphQLSchemaElement>> nodeToZipper) -
zipperWithSameParent
private Map<NodeZipper<GraphQLSchemaElement>,Breadcrumb<GraphQLSchemaElement>> zipperWithSameParent(GraphQLSchemaElement parent, SchemaTransformer.RelevantZippersAndBreadcrumbs relevantZippers, boolean cleanup) -
moveUp
private NodeZipper<GraphQLSchemaElement> moveUp(GraphQLSchemaElement parent, Map<NodeZipper<GraphQLSchemaElement>, Breadcrumb<GraphQLSchemaElement>> sameParentsZipper)
-