use of graphql.schema.GraphQLDirective in project graphql-java by graphql-java.
the class DirectivesUtil method directiveWithArg.
public static Optional<GraphQLArgument> directiveWithArg(List<GraphQLDirective> directiveList, String directiveName, String argumentName) {
GraphQLDirective directive = directivesByName(directiveList).get(directiveName);
GraphQLArgument argument = null;
if (directive != null) {
argument = directive.getArgument(argumentName);
}
return Optional.ofNullable(argument);
}
use of graphql.schema.GraphQLDirective in project graphql-java by graphql-java.
the class SchemaPrinter method directivesString.
private String directivesString(List<GraphQLDirective> directives) {
StringBuilder sb = new StringBuilder();
if (!directives.isEmpty()) {
sb.append(" ");
}
directives = directives.stream().sorted(Comparator.comparing(GraphQLDirective::getName)).collect(toList());
for (int i = 0; i < directives.size(); i++) {
GraphQLDirective directive = directives.get(i);
sb.append(directiveString(directive));
if (i < directives.size() - 1) {
sb.append(" ");
}
}
return sb.toString();
}
use of graphql.schema.GraphQLDirective 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);
}
}
}
Aggregations