Search in sources :

Example 6 with GraphQLDirective

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);
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument) GraphQLDirective(graphql.schema.GraphQLDirective)

Example 7 with GraphQLDirective

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();
}
Also used : GraphQLDirective(graphql.schema.GraphQLDirective)

Example 8 with GraphQLDirective

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);
        }
    }
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument) Argument(graphql.language.Argument) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLArgument(graphql.schema.GraphQLArgument) GraphQLDirective(graphql.schema.GraphQLDirective)

Aggregations

GraphQLDirective (graphql.schema.GraphQLDirective)8 GraphQLArgument (graphql.schema.GraphQLArgument)4 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)2 Argument (graphql.language.Argument)1 Directive (graphql.language.Directive)1 Node (graphql.language.Node)1 GraphQLNonNull (graphql.schema.GraphQLNonNull)1 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1