Search in sources :

Example 1 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project graphql-java by graphql-java.

the class SchemaGeneratorHelper method buildDirective.

// builds directives from a type and its extensions
public GraphQLDirective buildDirective(Directive directive, Introspection.DirectiveLocation directiveLocation) {
    List<GraphQLArgument> arguments = directive.getArguments().stream().map(this::buildDirectiveArgument).collect(Collectors.toList());
    GraphQLDirective.Builder builder = GraphQLDirective.newDirective().name(directive.getName()).description(buildDescription(directive, null)).validLocations(directiveLocation);
    for (GraphQLArgument argument : arguments) {
        builder.argument(argument);
    }
    return builder.build();
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument) GraphQLDirective(graphql.schema.GraphQLDirective)

Example 2 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project graphql-java by graphql-java.

the class ArgumentsOfCorrectType method checkArgument.

@Override
public void checkArgument(Argument argument) {
    GraphQLArgument fieldArgument = getValidationContext().getArgument();
    if (fieldArgument == null)
        return;
    ArgumentValidationUtil validationUtil = new ArgumentValidationUtil(argument);
    if (!validationUtil.isValidLiteralValue(argument.getValue(), fieldArgument.getType(), getValidationContext().getSchema())) {
        addError(ValidationErrorType.WrongType, argument.getSourceLocation(), validationUtil.getMessage());
    }
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument) ArgumentValidationUtil(graphql.validation.ArgumentValidationUtil)

Example 3 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project graphql-java by graphql-java.

the class KnownArgumentNames method checkArgument.

@Override
public void checkArgument(Argument argument) {
    GraphQLDirective directiveDef = getValidationContext().getDirective();
    if (directiveDef != null) {
        GraphQLArgument directiveArgument = directiveDef.getArgument(argument.getName());
        if (directiveArgument == null) {
            String message = String.format("Unknown directive argument %s", argument.getName());
            addError(ValidationErrorType.UnknownDirective, argument.getSourceLocation(), message);
        }
        return;
    }
    GraphQLFieldDefinition fieldDef = getValidationContext().getFieldDef();
    if (fieldDef == null)
        return;
    GraphQLArgument fieldArgument = fieldDef.getArgument(argument.getName());
    if (fieldArgument == null) {
        String message = String.format("Unknown field argument %s", argument.getName());
        addError(ValidationErrorType.UnknownArgument, argument.getSourceLocation(), message);
    }
}
Also used : GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLArgument(graphql.schema.GraphQLArgument) GraphQLDirective(graphql.schema.GraphQLDirective)

Example 4 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project graphql-java by graphql-java.

the class NoUnbrokenInputCycles method check.

@Override
public void check(GraphQLFieldDefinition fieldDef, SchemaValidationErrorCollector validationErrorCollector) {
    for (GraphQLArgument argument : fieldDef.getArguments()) {
        GraphQLInputType argumentType = argument.getType();
        if (argumentType instanceof GraphQLInputObjectType) {
            List<String> path = new ArrayList<>();
            path.add(argumentType.getName());
            check((GraphQLInputObjectType) argumentType, new HashSet<>(), path, validationErrorCollector);
        }
    }
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) ArrayList(java.util.ArrayList) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 5 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project graphql-java by graphql-java.

the class ValuesResolver method getArgumentValues.

public Map<String, Object> getArgumentValues(GraphqlFieldVisibility fieldVisibility, List<GraphQLArgument> argumentTypes, List<Argument> arguments, Map<String, Object> variables) {
    if (argumentTypes.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<String, Object> result = new LinkedHashMap<>();
    Map<String, Argument> argumentMap = argumentMap(arguments);
    for (GraphQLArgument fieldArgument : argumentTypes) {
        String argName = fieldArgument.getName();
        Argument argument = argumentMap.get(argName);
        Object value;
        if (argument != null) {
            value = coerceValueAst(fieldVisibility, fieldArgument.getType(), argument.getValue(), variables);
        } else {
            value = fieldArgument.getDefaultValue();
        }
        // the default value ended up being something non null
        if (argumentMap.containsKey(argName) || value != null) {
            result.put(argName, value);
        }
    }
    return result;
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument) Argument(graphql.language.Argument) GraphQLArgument(graphql.schema.GraphQLArgument) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

GraphQLArgument (graphql.schema.GraphQLArgument)15 GraphQLDirective (graphql.schema.GraphQLDirective)5 GraphQLInputType (graphql.schema.GraphQLInputType)5 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)4 GraphQLNonNull (graphql.schema.GraphQLNonNull)4 Argument (graphql.language.Argument)3 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)2 GraphQLList (graphql.schema.GraphQLList)2 GraphQLObjectType (graphql.schema.GraphQLObjectType)2 GraphQLOutputType (graphql.schema.GraphQLOutputType)2 GraphQLScalarType (graphql.schema.GraphQLScalarType)2 GraphQLUnionType (graphql.schema.GraphQLUnionType)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Lists (com.google.common.collect.Lists)1 Assert (graphql.Assert)1 PublicApi (graphql.PublicApi)1 Scalars (graphql.Scalars)1