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);
}
}
}
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;
}
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())));
}
}
}
}
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();
}
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();
}
Aggregations