use of graphql.analysis.QueryTraversal in project graphql-java by graphql-java.
the class FieldValidationSupport method validateFieldsAndArguments.
static List<GraphQLError> validateFieldsAndArguments(FieldValidation fieldValidation, ExecutionContext executionContext) {
Map<ExecutionPath, List<FieldAndArguments>> fieldArgumentsMap = new LinkedHashMap<>();
QueryTraversal queryTraversal = new QueryTraversal(executionContext.getGraphQLSchema(), executionContext.getDocument(), executionContext.getOperationDefinition().getName(), executionContext.getVariables());
queryTraversal.visitPreOrder(traversalEnv -> {
Field field = traversalEnv.getField();
if (field.getArguments() != null && !field.getArguments().isEmpty()) {
//
// only fields that have arguments make any sense to placed in play
// since only they have variable input
FieldAndArguments fieldArguments = new FieldAndArgumentsImpl(traversalEnv);
ExecutionPath path = fieldArguments.getPath();
List<FieldAndArguments> list = fieldArgumentsMap.getOrDefault(path, new ArrayList<>());
list.add(fieldArguments);
fieldArgumentsMap.put(path, list);
}
});
FieldValidationEnvironment environment = new FieldValidationEnvironmentImpl(executionContext, fieldArgumentsMap);
// this will allow a consumer to plugin their own validation of fields and arguments
return fieldValidation.validateFields(environment);
}
Aggregations