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