public class DataFetcherExecutionPredicate
Perform runtime evaluations of each parameter passed to any KotlinDataFetcher.
The DataFetcherExecutionPredicate is declared globally for all the datafetchers instances and all the parameters.
However a more precise logic (at the field level) is possible depending on the implement of evaluate
and test
The predicate logic is split into two parts (evaluate and test) so the result of the evaluation like a list of errors can be passed to the onFailure method and added to an exception
Because the DataFetcherExecutionPredicate is global, it's not possible to have methods where the type is inferred.
It's recommended to check the type of the different arguments.
Constructor and Description |
---|
DataFetcherExecutionPredicate()
Perform runtime evaluations of each parameter passed to any KotlinDataFetcher.
|
Modifier and Type | Method and Description |
---|---|
<T> java.lang.Object |
evaluate(T value,
Parameter parameter,
java.lang.String argumentName,
graphql.schema.DataFetchingEnvironment environment)
Evaluate if the value passed respects some constraints.
|
<T> T |
execute(T value,
Parameter parameter,
java.lang.String argumentName,
graphql.schema.DataFetchingEnvironment environment)
Perform the predicate logic by evaluating the argument and its value
Then depending on the result either returning the value itself to continue the datafetcher invocation
or break the data fetching execution.
|
java.lang.Void |
onFailure(java.lang.Object evaluationResult,
Parameter parameter,
java.lang.String argumentName,
graphql.schema.DataFetchingEnvironment environment)
If the test is unsuccessful, this function will be invoked.
|
boolean |
test(java.lang.Object evaluationResult)
Assert that the result of the {@link #evaluate(T, Parameter, String, DataFetchingEnvironment)} method is as expected eg: the list of errors is empty
|
public DataFetcherExecutionPredicate()
Perform runtime evaluations of each parameter passed to any KotlinDataFetcher.
The DataFetcherExecutionPredicate is declared globally for all the datafetchers instances and all the parameters.
However a more precise logic (at the field level) is possible depending on the implement of evaluate
and test
The predicate logic is split into two parts (evaluate and test) so the result of the evaluation like a list of errors can be passed to the onFailure method and added to an exception
Because the DataFetcherExecutionPredicate is global, it's not possible to have methods where the type is inferred.
It's recommended to check the type of the different arguments.
public <T> T execute(T value, Parameter parameter, java.lang.String argumentName, graphql.schema.DataFetchingEnvironment environment)
Perform the predicate logic by evaluating the argument and its value Then depending on the result either returning the value itself to continue the datafetcher invocation or break the data fetching execution.
parameter
- the function argument reference containing the KClass and the argument annotationsargumentName
- the name of the argument as declared in the query / kotlin functionenvironment
- the DataFetchingEnvironment in which the data fetcher is executed (gives access to field info, execution context etc)value
- the value to execute the predicate against.public <T> java.lang.Object evaluate(T value, Parameter parameter, java.lang.String argumentName, graphql.schema.DataFetchingEnvironment environment)
Evaluate if the value passed respects some constraints.
parameter
- the function argument reference containing the KClass and the argument annotationsargumentName
- the name of the argument as declared in the query / kotlin functionenvironment
- the DataFetchingEnvironment in which the data fetcher is executed (gives access to field info, execution context etc)value
- the value to execute the predicate against.public boolean test(java.lang.Object evaluationResult)
Assert that the result of the {@link #evaluate(T, Parameter, String, DataFetchingEnvironment)} method is as expected eg: the list of errors is empty
evaluationResult
- the result of the evaluationpublic java.lang.Void onFailure(java.lang.Object evaluationResult, Parameter parameter, java.lang.String argumentName, graphql.schema.DataFetchingEnvironment environment)
If the test is unsuccessful, this function will be invoked.
An exception can then be thrown to block the data fetcher execution
evaluationResult
- the object return by the evaluate
functionparameter
- the function argument reference containing the KClass and the argument annotationsargumentName
- the name of the argument as declared in the query / kotlin functionenvironment
- the DataFetchingEnvironment in which the data fetcher is executed (gives access to field info, execution context etc)