Package graphql.analysis
Class QueryTraverser
java.lang.Object
graphql.analysis.QueryTraverser
Helps to traverse (or reduce) a Document (or parts of it) and tracks at the same time the corresponding Schema types.
This is an important distinction to just traversing the Document without any type information: Each field has a clearly
defined type. See QueryVisitorFieldEnvironment
.
Furthermore are the built in Directives skip/include automatically evaluated: if parts of the Document should be ignored they will not be visited. But this is not a full evaluation of a Query: every fragment will be visited/followed regardless of the type condition.
It also doesn't consider field merging, which means for example { user{firstName} user{firstName}}
will result in four
visitField calls.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CoercedVariables
private final Map
<String, FragmentDefinition> private final GraphQLCompositeType
private final Collection
<? extends Node> private final GraphQLSchema
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
QueryTraverser
(GraphQLSchema schema, Document document, String operation, CoercedVariables coercedVariables) private
QueryTraverser
(GraphQLSchema schema, Document document, String operation, RawVariables rawVariables) private
QueryTraverser
(GraphQLSchema schema, Node root, GraphQLCompositeType rootParentType, Map<String, FragmentDefinition> fragmentsByName, CoercedVariables coercedVariables) -
Method Summary
Modifier and TypeMethodDescriptionchildrenOf
(Node<?> node) private GraphQLObjectType
getRootTypeFromOperation
(OperationDefinition operationDefinition) static QueryTraverser.Builder
<T> T
reducePostOrder
(QueryReducer<T> queryReducer, T initialValue) Reduces the fields of a Document (or parts of it) to a single value.<T> T
reducePreOrder
(QueryReducer<T> queryReducer, T initialValue) Reduces the fields of a Document (or parts of it) to a single value.visitDepthFirst
(QueryVisitor queryVisitor) private Object
visitImpl
(QueryVisitor visitFieldCallback, Boolean preOrder) void
visitPostOrder
(QueryVisitor visitor) Visits the Document (or parts of it) in post-order.void
visitPreOrder
(QueryVisitor visitor) Visits the Document (or parts of it) in pre-order.
-
Field Details
-
roots
-
schema
-
fragmentsByName
-
coercedVariables
-
rootParentType
-
-
Constructor Details
-
QueryTraverser
private QueryTraverser(GraphQLSchema schema, Document document, String operation, CoercedVariables coercedVariables) -
QueryTraverser
private QueryTraverser(GraphQLSchema schema, Document document, String operation, RawVariables rawVariables) -
QueryTraverser
private QueryTraverser(GraphQLSchema schema, Node root, GraphQLCompositeType rootParentType, Map<String, FragmentDefinition> fragmentsByName, CoercedVariables coercedVariables)
-
-
Method Details
-
visitDepthFirst
-
visitPostOrder
Visits the Document (or parts of it) in post-order.- Parameters:
visitor
- the query visitor that will be called back
-
visitPreOrder
Visits the Document (or parts of it) in pre-order.- Parameters:
visitor
- the query visitor that will be called back
-
reducePostOrder
Reduces the fields of a Document (or parts of it) to a single value. The fields are visited in post-order.- Type Parameters:
T
- the type of reduced value- Parameters:
queryReducer
- the query reducerinitialValue
- the initial value to pass to the reducer- Returns:
- the calculated overall value
-
reducePreOrder
Reduces the fields of a Document (or parts of it) to a single value. The fields are visited in pre-order.- Type Parameters:
T
- the type of reduced value- Parameters:
queryReducer
- the query reducerinitialValue
- the initial value to pass to the reducer- Returns:
- the calculated overall value
-
getRootTypeFromOperation
-
childrenOf
-
visitImpl
-
newQueryTraverser
-