private boolean inRightLocation(DirectiveLocation expectedLocation, DirectiveDefinition directiveDefinition) { List<String> names = directiveDefinition.getDirectiveLocations() .stream().map(graphql.language.DirectiveLocation::getName) .map(String::toUpperCase) .collect(Collectors.toList()); return names.contains(expectedLocation.name().toUpperCase()); }
private List<DirectiveLocation> buildLocations(DirectiveDefinition directiveDefinition) { return directiveDefinition.getDirectiveLocations().stream() .map(dl -> DirectiveLocation.valueOf(dl.getName().toUpperCase())) .collect(Collectors.toList()); }
private void checkDirectiveDefinitions(TypeDefinitionRegistry typeRegistry, List<GraphQLError> errors) { List<DirectiveDefinition> directiveDefinitions = new ArrayList<>(typeRegistry.getDirectiveDefinitions().values()); directiveDefinitions.forEach(directiveDefinition -> { List<InputValueDefinition> arguments = directiveDefinition.getInputValueDefinitions(); checkNamedUniqueness(errors, arguments, InputValueDefinition::getName, (name, arg) -> new NonUniqueNameError(directiveDefinition, arg)); List<Type> inputValueTypes = arguments.stream() .map(InputValueDefinition::getType) .collect(Collectors.toList()); inputValueTypes.forEach( checkTypeExists(typeRegistry, errors, "directive definition", directiveDefinition, directiveDefinition.getName()) ); directiveDefinition.getDirectiveLocations().forEach(directiveLocation -> { String locationName = directiveLocation.getName(); try { Introspection.DirectiveLocation.valueOf(locationName); } catch (IllegalArgumentException e) { errors.add(new DirectiveIllegalLocationError(directiveDefinition, locationName)); } }); }); }
private NodePrinter<DirectiveDefinition> directiveDefinition() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { String arguments = wrap("(", join(node.getInputValueDefinitions(), argSep), ")"); String locations = join(node.getDirectiveLocations(), " | "); out.printf("directive @%s%s on %s", node.getName(), arguments, locations); }; }
@Override public TraversalControl visitDirectiveDefinition(DirectiveDefinition node, TraverserContext<Node> context) { DirectiveDefinition changedNode = node.transform(builder -> { builder.inputValueDefinitions(sort(node.getInputValueDefinitions(), comparing(InputValueDefinition::getName))); builder.directiveLocations(sort(node.getDirectiveLocations(), comparing(DirectiveLocation::getName))); }); return changeNode(context, changedNode); } };
private Builder(DirectiveDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.description = existing.getDescription(); this.inputValueDefinitions = existing.getInputValueDefinitions(); this.directiveLocations = existing.getDirectiveLocations(); this.ignoredChars = existing.getIgnoredChars(); }
private boolean inRightLocation(DirectiveLocation expectedLocation, DirectiveDefinition directiveDefinition) { List<String> names = directiveDefinition.getDirectiveLocations() .stream().map(graphql.language.DirectiveLocation::getName) .map(String::toUpperCase) .collect(Collectors.toList()); return names.contains(expectedLocation.name().toUpperCase()); }
private List<DirectiveLocation> buildLocations(DirectiveDefinition directiveDefinition) { return directiveDefinition.getDirectiveLocations().stream() .map(dl -> DirectiveLocation.valueOf(dl.getName().toUpperCase())) .collect(Collectors.toList()); }
private void checkDirectiveDefinitions(TypeDefinitionRegistry typeRegistry, List<GraphQLError> errors) { List<DirectiveDefinition> directiveDefinitions = new ArrayList<>(typeRegistry.getDirectiveDefinitions().values()); directiveDefinitions.forEach(directiveDefinition -> { List<InputValueDefinition> arguments = directiveDefinition.getInputValueDefinitions(); checkNamedUniqueness(errors, arguments, InputValueDefinition::getName, (name, arg) -> new NonUniqueNameError(directiveDefinition, arg)); List<Type> inputValueTypes = arguments.stream() .map(InputValueDefinition::getType) .collect(Collectors.toList()); inputValueTypes.forEach( checkTypeExists(typeRegistry, errors, "directive definition", directiveDefinition, directiveDefinition.getName()) ); directiveDefinition.getDirectiveLocations().forEach(directiveLocation -> { String locationName = directiveLocation.getName(); try { Introspection.DirectiveLocation.valueOf(locationName); } catch (IllegalArgumentException e) { errors.add(new DirectiveIllegalLocationError(directiveDefinition, locationName)); } }); }); }
private NodePrinter<DirectiveDefinition> directiveDefinition() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { String arguments = wrap("(", join(node.getInputValueDefinitions(), argSep), ")"); String locations = join(node.getDirectiveLocations(), " | "); out.printf("directive @%s%s on %s", node.getName(), arguments, locations); }; }
@Override public TraversalControl visitDirectiveDefinition(DirectiveDefinition node, TraverserContext<Node> context) { DirectiveDefinition changedNode = node.transform(builder -> { builder.inputValueDefinitions(sort(node.getInputValueDefinitions(), comparing(InputValueDefinition::getName))); builder.directiveLocations(sort(node.getDirectiveLocations(), comparing(DirectiveLocation::getName))); }); return changeNode(context, changedNode); } };
private Builder(DirectiveDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.description = existing.getDescription(); this.inputValueDefinitions = existing.getInputValueDefinitions(); this.directiveLocations = existing.getDirectiveLocations(); this.ignoredChars = existing.getIgnoredChars(); }