Search in sources :

Example 1 with DirectiveUnknownArgumentError

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

the class SchemaTypeDirectivesChecker method checkDirectiveArguments.

private void checkDirectiveArguments(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, Node element, String elementName, Directive directive, DirectiveDefinition directiveDefinition) {
    Map<String, InputValueDefinition> allowedArgs = getByName(directiveDefinition.getInputValueDefinitions(), (InputValueDefinition::getName), mergeFirst());
    Map<String, Argument> providedArgs = getByName(directive.getArguments(), (Argument::getName), mergeFirst());
    directive.getArguments().forEach(argument -> {
        InputValueDefinition allowedArg = allowedArgs.get(argument.getName());
        if (allowedArg == null) {
            errors.add(new DirectiveUnknownArgumentError(element, elementName, directive.getName(), argument.getName()));
        } else {
            ArgValueOfAllowedTypeChecker argValueOfAllowedTypeChecker = new ArgValueOfAllowedTypeChecker(directive, element, elementName, argument, typeRegistry, runtimeWiring);
            argValueOfAllowedTypeChecker.checkArgValueMatchesAllowedType(errors, argument.getValue(), allowedArg.getType());
        }
    });
    allowedArgs.forEach((argName, definitionArgument) -> {
        if (isNoNullArgWithoutDefaultValue(definitionArgument)) {
            if (!providedArgs.containsKey(argName)) {
                errors.add(new DirectiveMissingNonNullArgumentError(element, elementName, directive.getName(), argName));
            }
        }
    });
}
Also used : Argument(graphql.language.Argument) DirectiveUnknownArgumentError(graphql.schema.idl.errors.DirectiveUnknownArgumentError) DirectiveMissingNonNullArgumentError(graphql.schema.idl.errors.DirectiveMissingNonNullArgumentError) InputValueDefinition(graphql.language.InputValueDefinition)

Aggregations

Argument (graphql.language.Argument)1 InputValueDefinition (graphql.language.InputValueDefinition)1 DirectiveMissingNonNullArgumentError (graphql.schema.idl.errors.DirectiveMissingNonNullArgumentError)1 DirectiveUnknownArgumentError (graphql.schema.idl.errors.DirectiveUnknownArgumentError)1