Search in sources :

Example 11 with GraphQLArgument

use of graphql.schema.GraphQLArgument 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 12 with GraphQLArgument

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

the class TraversalContext method enterImpl.

private void enterImpl(Argument argument) {
    GraphQLArgument argumentType = null;
    if (getDirective() != null) {
        argumentType = find(getDirective().getArguments(), argument.getName());
    } else if (getFieldDef() != null) {
        argumentType = find(getFieldDef().getArguments(), argument.getName());
    }
    addInputType(argumentType != null ? argumentType.getType() : null);
    this.argument = argumentType;
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument)

Example 13 with GraphQLArgument

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

the class ObjectsImplementInterfaces method checkFieldArgumentEquivalence.

private void checkFieldArgumentEquivalence(GraphQLObjectType objectTyoe, GraphQLInterfaceType interfaceType, SchemaValidationErrorCollector validationErrorCollector, GraphQLFieldDefinition interfaceFieldDef, GraphQLFieldDefinition objectFieldDef) {
    List<GraphQLArgument> interfaceArgs = interfaceFieldDef.getArguments();
    List<GraphQLArgument> objectArgs = objectFieldDef.getArguments();
    if (interfaceArgs.size() != objectArgs.size()) {
        validationErrorCollector.addError(error(format("object type '%s' does not implement interface '%s' because field '%s' has a different number of arguments", objectTyoe.getName(), interfaceType.getName(), interfaceFieldDef.getName())));
    } else {
        for (int i = 0; i < interfaceArgs.size(); i++) {
            GraphQLArgument interfaceArg = interfaceArgs.get(i);
            GraphQLArgument objectArg = objectArgs.get(i);
            String interfaceArgStr = makeArgStr(interfaceArg);
            String objectArgStr = makeArgStr(objectArg);
            boolean same = true;
            if (!interfaceArgStr.equals(objectArgStr)) {
                same = false;
            }
            if (!Objects.equals(interfaceArg.getDefaultValue(), objectArg.getDefaultValue())) {
                same = false;
            }
            if (!same) {
                validationErrorCollector.addError(error(format("object type '%s' does not implement interface '%s' because field '%s' argument '%s' is defined differently", objectTyoe.getName(), interfaceType.getName(), interfaceFieldDef.getName(), interfaceArg.getName())));
            }
        }
    }
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument)

Example 14 with GraphQLArgument

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

the class SchemaGenerator method buildArgument.

private GraphQLArgument buildArgument(BuildContext buildCtx, InputValueDefinition valueDefinition) {
    GraphQLArgument.Builder builder = GraphQLArgument.newArgument();
    builder.definition(valueDefinition);
    builder.name(valueDefinition.getName());
    builder.description(schemaGeneratorHelper.buildDescription(valueDefinition, valueDefinition.getDescription()));
    GraphQLInputType inputType = buildInputType(buildCtx, valueDefinition.getType());
    builder.type(inputType);
    Value defaultValue = valueDefinition.getDefaultValue();
    if (defaultValue != null) {
        builder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType));
    }
    return builder.build();
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) Value(graphql.language.Value) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 15 with GraphQLArgument

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

the class SchemaGeneratorHelper method buildDirectiveArgument.

private GraphQLArgument buildDirectiveArgument(Argument arg) {
    GraphQLArgument.Builder builder = GraphQLArgument.newArgument();
    builder.name(arg.getName());
    GraphQLInputType inputType = buildDirectiveInputType(arg.getValue());
    builder.type(inputType);
    builder.defaultValue(buildValue(arg.getValue(), inputType));
    return builder.build();
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLArgument(graphql.schema.GraphQLArgument)

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