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