Search in sources :

Example 1 with DirectiveIllegalLocationError

use of graphql.schema.idl.errors.DirectiveIllegalLocationError in project graphql-java by graphql-java.

the class SchemaTypeChecker method checkDirectiveDefinitions.

private void checkDirectiveDefinitions(TypeDefinitionRegistry typeRegistry, List<GraphQLError> errors) {
    List<DirectiveDefinition> directiveDefinitions = new ArrayList<>(typeRegistry.getDirectiveDefinitions().values());
    directiveDefinitions.forEach(directiveDefinition -> {
        List<InputValueDefinition> arguments = directiveDefinition.getInputValueDefinitions();
        checkNamedUniqueness(errors, arguments, InputValueDefinition::getName, (name, arg) -> new NonUniqueNameError(directiveDefinition, arg));
        List<Type> inputValueTypes = arguments.stream().map(InputValueDefinition::getType).collect(toList());
        inputValueTypes.forEach(checkTypeExists(typeRegistry, errors, "directive definition", directiveDefinition, directiveDefinition.getName()));
        directiveDefinition.getDirectiveLocations().forEach(directiveLocation -> {
            String locationName = directiveLocation.getName();
            try {
                Introspection.DirectiveLocation.valueOf(locationName);
            } catch (IllegalArgumentException e) {
                errors.add(new DirectiveIllegalLocationError(directiveDefinition, locationName));
            }
        });
    });
}
Also used : Type(graphql.language.Type) DirectiveIllegalLocationError(graphql.schema.idl.errors.DirectiveIllegalLocationError) ArrayList(java.util.ArrayList) DirectiveDefinition(graphql.language.DirectiveDefinition) InputValueDefinition(graphql.language.InputValueDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Aggregations

DirectiveDefinition (graphql.language.DirectiveDefinition)1 InputValueDefinition (graphql.language.InputValueDefinition)1 Type (graphql.language.Type)1 DirectiveIllegalLocationError (graphql.schema.idl.errors.DirectiveIllegalLocationError)1 NonUniqueNameError (graphql.schema.idl.errors.NonUniqueNameError)1 ArrayList (java.util.ArrayList)1