use of graphql.analysis.QueryVisitorStub in project graphql-java by graphql-java.
the class FieldValidationSupport method validateFieldsAndArguments.
static List<GraphQLError> validateFieldsAndArguments(FieldValidation fieldValidation, ExecutionContext executionContext) {
Map<ResultPath, List<FieldAndArguments>> fieldArgumentsMap = new LinkedHashMap<>();
QueryTraverser queryTraverser = QueryTraverser.newQueryTraverser().schema(executionContext.getGraphQLSchema()).document(executionContext.getDocument()).operationName(executionContext.getOperationDefinition().getName()).variables(executionContext.getVariables()).build();
queryTraverser.visitPreOrder(new QueryVisitorStub() {
@Override
public void visitField(QueryVisitorFieldEnvironment env) {
Field field = env.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(env);
ResultPath 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