Class SchemaTransformer
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiontransform(GraphQLSchema schema, GraphQLTypeVisitor visitor) transform(GraphQLSchema schema, GraphQLTypeVisitor visitor, Consumer<GraphQLSchema.Builder> postTransformation) <T extends GraphQLSchemaElement>
Ttransform(T schemaElement, GraphQLTypeVisitor visitor) static GraphQLSchematransformSchema(GraphQLSchema schema, GraphQLTypeVisitor visitor) Transforms a GraphQLSchema and returns a new GraphQLSchema object.static GraphQLSchematransformSchema(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 aGraphQLSchemaElementand returns a new element.static GraphQLSchematransformSchemaWithDeletes(GraphQLSchema schema, GraphQLTypeVisitor visitor) Transforms a GraphQLSchema with support for delete operations.static GraphQLSchematransformSchemaWithDeletes(GraphQLSchema schema, GraphQLTypeVisitor visitor, Consumer<GraphQLSchema.Builder> postTransformation) Transforms a GraphQLSchema with support for delete operations.
-
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.
-
transformSchemaWithDeletes
public static GraphQLSchema transformSchemaWithDeletes(GraphQLSchema schema, GraphQLTypeVisitor visitor) Transforms a GraphQLSchema with support for delete operations.When a visitor uses
GraphQLTypeVisitor.deleteNode(TraverserContext)to delete schema elements, the traversal does not continue to the children of deleted nodes. This can cause issues when types are only reachable through fields that get deleted, as those types won't be visited and transformed.This method ensures all types in the schema are visited by temporarily adding them as extra root types during transformation. This guarantees that even types only reachable through deleted fields will be properly visited and transformed.
Use this method instead of
transformSchema(GraphQLSchema, GraphQLTypeVisitor)when your visitor deletes fields or types that may reference other types via circular dependencies.- Parameters:
schema- the schema to transformvisitor- the visitor call back- Returns:
- a new GraphQLSchema instance.
- See Also:
-
transformSchemaWithDeletes
public static GraphQLSchema transformSchemaWithDeletes(GraphQLSchema schema, GraphQLTypeVisitor visitor, Consumer<GraphQLSchema.Builder> postTransformation) Transforms a GraphQLSchema with support for delete operations.When a visitor uses
GraphQLTypeVisitor.deleteNode(TraverserContext)to delete schema elements, the traversal does not continue to the children of deleted nodes. This can cause issues when types are only reachable through fields that get deleted, as those types won't be visited and transformed.This method ensures all types in the schema are visited by temporarily adding them as extra root types during transformation. This guarantees that even types only reachable through deleted fields will be properly visited and transformed.
Use this method instead of
transformSchema(GraphQLSchema, GraphQLTypeVisitor, Consumer)when your visitor deletes fields or types that may reference other types via circular dependencies.- Parameters:
schema- the schema to transformvisitor- the visitor call backpostTransformation- a callback that can be used as a final step to the schema (can be null)- Returns:
- a new GraphQLSchema instance.
- See Also:
-
transformSchema
public static <T extends GraphQLSchemaElement> T transformSchema(T schemaElement, GraphQLTypeVisitor visitor) Transforms aGraphQLSchemaElementand 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
-