Class ValueTraverser
If you just want to traverse without changing anything, just return the value presented to you and nothing will change.
If you want to change a value, perhaps in the presence of a directive say on the containing element, then return a new value back in your visitor.
This class is intended to be used say inside a DataFetcher, allowing you to change the DataFetchingEnvironment.getArguments()
say before further processing.
The values passed in are assumed to be valid and coerced. This classes does not check for non nullness say or the right coerced objects given the type system. This is assumed to have occurred earlier in the graphql validation phase. This also means if you are not careful you can undo the validation that has gone before you. For example, it would be possible to change values that are illegal according to the type system, such as null values for non-nullable types say, so you need to be careful.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DataFetchingEnvironment
visitPreOrder
(DataFetchingEnvironment environment, ValueVisitor visitor) This will visit the arguments of aDataFetchingEnvironment
and if the values are changed by the visitor a new environment will be builtstatic Object
visitPreOrder
(Object coercedArgumentValue, GraphQLAppliedDirectiveArgument argument, ValueVisitor visitor) This will visit a single argument of aGraphQLAppliedDirective
and if the visitor changes the value, it will return a new argument valuestatic Object
visitPreOrder
(Object coercedArgumentValue, GraphQLArgument argument, ValueVisitor visitor) This will visit a single argument of aGraphQLArgument
and if the visitor changes the value, it will return a new argument valuevisitPreOrder
(Map<String, Object> coercedArgumentValues, GraphQLFieldDefinition fieldDefinition, ValueVisitor visitor) This will visit the arguments of aGraphQLFieldDefinition
and if the visitor changes the values, it will return a new set of arguments
-
Constructor Details
-
ValueTraverser
public ValueTraverser()
-
-
Method Details
-
visitPreOrder
public static DataFetchingEnvironment visitPreOrder(DataFetchingEnvironment environment, ValueVisitor visitor) This will visit the arguments of aDataFetchingEnvironment
and if the values are changed by the visitor a new environment will be built- Parameters:
environment
- the starting data fetching environmentvisitor
- the visitor to use- Returns:
- the same environment if nothing changes or a new one with the
DataFetchingEnvironment.getArguments()
changed
-
visitPreOrder
public static Map<String,Object> visitPreOrder(Map<String, Object> coercedArgumentValues, GraphQLFieldDefinition fieldDefinition, ValueVisitor visitor) This will visit the arguments of aGraphQLFieldDefinition
and if the visitor changes the values, it will return a new set of arguments- Parameters:
coercedArgumentValues
- the starting coerced argumentsfieldDefinition
- the field definitionvisitor
- the visitor to use- Returns:
- the same set of arguments if nothing changes or new ones if the visitor changes anything
-
visitPreOrder
public static Object visitPreOrder(Object coercedArgumentValue, GraphQLArgument argument, ValueVisitor visitor) This will visit a single argument of aGraphQLArgument
and if the visitor changes the value, it will return a new argument valueNote you cannot return the ABSENCE_SENTINEL from this method as its makes no sense to be somehow make the argument disappear. Use
visitPreOrder(Map, GraphQLFieldDefinition, ValueVisitor)
say to remove arguments in the fields map of arguments.- Parameters:
coercedArgumentValue
- the starting coerced argument valueargument
- the argument definitionvisitor
- the visitor to use- Returns:
- the same value if nothing changes or a new value if the visitor changes anything
-
visitPreOrder
public static Object visitPreOrder(Object coercedArgumentValue, GraphQLAppliedDirectiveArgument argument, ValueVisitor visitor) This will visit a single argument of aGraphQLAppliedDirective
and if the visitor changes the value, it will return a new argument valueNote you cannot return the ABSENCE_SENTINEL from this method as its makes no sense to be somehow make the argument disappear.
- Parameters:
coercedArgumentValue
- the starting coerced argument valueargument
- the applied argumentvisitor
- the visitor to use- Returns:
- the same value if nothing changes or a new value if the visitor changes anything
-