Search in sources :

Example 1 with Node

use of graphql.language.Node in project graphql-java by graphql-java.

the class KnownDirectives method checkDirective.

@Override
public void checkDirective(Directive directive, List<Node> ancestors) {
    GraphQLDirective graphQLDirective = getValidationContext().getSchema().getDirective(directive.getName());
    if (graphQLDirective == null) {
        String message = String.format("Unknown directive %s", directive.getName());
        addError(ValidationErrorType.UnknownDirective, directive.getSourceLocation(), message);
        return;
    }
    Node ancestor = ancestors.get(ancestors.size() - 1);
    if (hasInvalidLocation(graphQLDirective, ancestor)) {
        String message = String.format("Directive %s not allowed here", directive.getName());
        addError(ValidationErrorType.MisplacedDirective, directive.getSourceLocation(), message);
    }
}
Also used : Node(graphql.language.Node) GraphQLDirective(graphql.schema.GraphQLDirective)

Example 2 with Node

use of graphql.language.Node in project graphql-java by graphql-java.

the class NoFragmentCycles method gatherSpreads.

private List<FragmentSpread> gatherSpreads(FragmentDefinition fragmentDefinition) {
    final List<FragmentSpread> fragmentSpreads = new ArrayList<>();
    DocumentVisitor visitor = new DocumentVisitor() {

        @Override
        public void enter(Node node, List<Node> path) {
            if (node instanceof FragmentSpread) {
                fragmentSpreads.add((FragmentSpread) node);
            }
        }

        @Override
        public void leave(Node node, List<Node> path) {
        }
    };
    new LanguageTraversal().traverse(fragmentDefinition, visitor);
    return fragmentSpreads;
}
Also used : DocumentVisitor(graphql.validation.DocumentVisitor) Node(graphql.language.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LanguageTraversal(graphql.validation.LanguageTraversal) FragmentSpread(graphql.language.FragmentSpread)

Example 3 with Node

use of graphql.language.Node in project graphql-java by graphql-java.

the class LanguageTraversal method traverseImpl.

private void traverseImpl(Node<?> root, DocumentVisitor documentVisitor, List<Node> path) {
    documentVisitor.enter(root, path);
    path.add(root);
    for (Node child : root.getChildren()) {
        traverseImpl(child, documentVisitor, path);
    }
    path.remove(path.size() - 1);
    documentVisitor.leave(root, path);
}
Also used : Node(graphql.language.Node)

Example 4 with Node

use of graphql.language.Node in project graphql-java by graphql-java.

the class SchemaPrinter method descriptionAndComments.

AstDescriptionAndComments descriptionAndComments(Supplier<String> stringSupplier, Supplier<Node> nodeSupplier, Supplier<Description> descriptionSupplier) {
    String runtimeDesc = stringSupplier.get();
    Node node = nodeSupplier.get();
    Description description = null;
    List<Comment> comments = null;
    if (node != null) {
        comments = node.getComments();
        description = descriptionSupplier.get();
    }
    return new AstDescriptionAndComments(runtimeDesc, description, comments);
}
Also used : Comment(graphql.language.Comment) Description(graphql.language.Description) Node(graphql.language.Node)

Example 5 with Node

use of graphql.language.Node in project graphql-java by graphql-java.

the class AbstractRule method addError.

public void addError(ValidationErrorType validationErrorType, List<? extends Node> locations, String description) {
    List<SourceLocation> locationList = new ArrayList<>();
    for (Node node : locations) {
        locationList.add(node.getSourceLocation());
    }
    validationErrorCollector.addError(new ValidationError(validationErrorType, locationList, description, getQueryPath()));
}
Also used : SourceLocation(graphql.language.SourceLocation) Node(graphql.language.Node) ArrayList(java.util.ArrayList)

Aggregations

Node (graphql.language.Node)6 ArrayList (java.util.ArrayList)2 Comment (graphql.language.Comment)1 Description (graphql.language.Description)1 Field (graphql.language.Field)1 FragmentSpread (graphql.language.FragmentSpread)1 OperationDefinition (graphql.language.OperationDefinition)1 Selection (graphql.language.Selection)1 SelectionSet (graphql.language.SelectionSet)1 SourceLocation (graphql.language.SourceLocation)1 GraphQLDirective (graphql.schema.GraphQLDirective)1 DocumentVisitor (graphql.validation.DocumentVisitor)1 LanguageTraversal (graphql.validation.LanguageTraversal)1 List (java.util.List)1