Search in sources :

Example 16 with Argument

use of graphql.language.Argument in project graphql-java by graphql-java.

the class ProvidedNonNullArguments method checkDirective.

@Override
public void checkDirective(Directive directive, List<Node> ancestors) {
    GraphQLDirective graphQLDirective = getValidationContext().getDirective();
    if (graphQLDirective == null)
        return;
    Map<String, Argument> argumentMap = argumentMap(directive.getArguments());
    for (GraphQLArgument graphQLArgument : graphQLDirective.getArguments()) {
        Argument argument = argumentMap.get(graphQLArgument.getName());
        if (argument == null && (graphQLArgument.getType() instanceof GraphQLNonNull)) {
            String message = String.format("Missing directive argument %s", graphQLArgument.getName());
            addError(ValidationErrorType.MissingDirectiveArgument, directive.getSourceLocation(), message);
        }
    }
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument) Argument(graphql.language.Argument) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLArgument(graphql.schema.GraphQLArgument) GraphQLDirective(graphql.schema.GraphQLDirective)

Example 17 with Argument

use of graphql.language.Argument in project graphql-java by graphql-java.

the class ProvidedNonNullArguments method checkField.

@Override
public void checkField(Field field) {
    GraphQLFieldDefinition fieldDef = getValidationContext().getFieldDef();
    if (fieldDef == null)
        return;
    Map<String, Argument> argumentMap = argumentMap(field.getArguments());
    for (GraphQLArgument graphQLArgument : fieldDef.getArguments()) {
        Argument argument = argumentMap.get(graphQLArgument.getName());
        if (argument == null && (graphQLArgument.getType() instanceof GraphQLNonNull)) {
            String message = String.format("Missing field argument %s", graphQLArgument.getName());
            addError(ValidationErrorType.MissingFieldArgument, field.getSourceLocation(), message);
        }
    }
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument) Argument(graphql.language.Argument) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 18 with Argument

use of graphql.language.Argument in project graphql-java by graphql-java.

the class GraphqlAntlrToLanguage method visitArgument.

@Override
public Void visitArgument(GraphqlParser.ArgumentContext ctx) {
    Argument argument = new Argument(ctx.name().getText(), getValue(ctx.valueWithVariable()));
    newNode(argument, ctx);
    if (getFromContextStack(ContextProperty.Directive, false) != null) {
        ((Directive) getFromContextStack(ContextProperty.Directive)).getArguments().add(argument);
    } else {
        Field field = (Field) getFromContextStack(ContextProperty.Field);
        field.getArguments().add(argument);
    }
    return super.visitArgument(ctx);
}
Also used : ObjectField(graphql.language.ObjectField) Field(graphql.language.Field) Argument(graphql.language.Argument)

Example 19 with Argument

use of graphql.language.Argument in project graphql-java by graphql-java.

the class IntrospectionResultToSchema method createDeprecatedDirective.

private void createDeprecatedDirective(Map<String, Object> field, List<Directive> directives) {
    if ((Boolean) field.get("isDeprecated")) {
        String reason = (String) field.get("deprecationReason");
        if (reason == null) {
            // default according to spec
            reason = "No longer supported";
        }
        Argument reasonArg = new Argument("reason", new StringValue(reason));
        Directive deprecated = new Directive("deprecated", Collections.singletonList(reasonArg));
        directives.add(deprecated);
    }
}
Also used : Argument(graphql.language.Argument) StringValue(graphql.language.StringValue) Directive(graphql.language.Directive)

Aggregations

Argument (graphql.language.Argument)19 Directive (graphql.language.Directive)9 StringValue (graphql.language.StringValue)9 List (java.util.List)9 Optional (java.util.Optional)9 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 GraphQLError (graphql.GraphQLError)7 Internal (graphql.Internal)7 AstPrinter (graphql.language.AstPrinter)7 EnumTypeDefinition (graphql.language.EnumTypeDefinition)7 EnumValueDefinition (graphql.language.EnumValueDefinition)7 FieldDefinition (graphql.language.FieldDefinition)7 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)7 InputValueDefinition (graphql.language.InputValueDefinition)7 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)7 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)7 Type (graphql.language.Type)7 TypeDefinition (graphql.language.TypeDefinition)7 TypeName (graphql.language.TypeName)7