private NodePrinter<Directive> directive() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { String arguments = wrap("(", join(node.getArguments(), argSep), ")"); out.printf("@%s%s", node.getName(), arguments); }; }
@Override public Directive deepCopy() { return new Directive(name, deepCopy(arguments), getSourceLocation(), getComments(), getIgnoredChars()); }
public Argument getArgument(String argumentName) { return getArgumentsByName().get(argumentName); }
private Builder(Directive existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.arguments = existing.getArguments(); this.ignoredChars = existing.getIgnoredChars(); }
private void enterImpl(Directive directive) { this.directive = schema.getDirective(directive.getName()); }
private boolean getDirectiveResult(Map<String, Object> variables, List<Directive> directives, String directiveName, boolean defaultValue) { Directive directive = getDirectiveByName(directives, directiveName); if (directive != null) { Map<String, Object> argumentValues = valuesResolver.getArgumentValues(SkipDirective.getArguments(), directive.getArguments(), variables); return (Boolean) argumentValues.get("if"); } return defaultValue; }
private void checkDirectivesUniqueness(Node<?> directivesContainer, List<Directive> directives) { Set<String> names = new LinkedHashSet<>(); directives.forEach(directive -> { String name = directive.getName(); if (names.contains(name)) { addError(ValidationErrorType.DuplicateDirectiveName, directive.getSourceLocation(), duplicateDirectiveNameMessage(name, directivesContainer.getClass().getSimpleName())); } else { names.add(name); } }); }
String iri = ((StringValue) field.getDirective("href").getArgument("iri").getValue()).getValue(); contextMap.put(field.getName(), iri); }); if (dir.getName().equals("service")) { String getQueryUri = typeUri + "_GET"; String getByIdQueryUri = typeUri + "_GET_BY_ID"; String serviceId = ((StringValue) dir.getArgument("id").getValue()).getValue(); rdfSchema.insertObjectTriple(typeUri, HGQL_HAS_FIELD, fieldURI); String serviceId = ((StringValue) field.getDirective("service").getArgument("id").getValue()).getValue(); String serviceURI = HGQL_SERVICE_NAMESPACE + serviceId; rdfSchema.insertObjectTriple(fieldURI, HGQL_HAS_SERVICE, serviceURI);
@Override public TraversalControl visitDirective(Directive node, TraverserContext<Node> context) { Directive changedNode = node.transform(builder -> { List<Argument> arguments = sort(node.getArguments(), comparing(Argument::getName)); builder.arguments(arguments); }); return changeNode(context, changedNode); }
@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 && (isNonNull(graphQLArgument.getType()))) { String message = String.format("Missing directive argument %s", graphQLArgument.getName()); addError(ValidationErrorType.MissingDirectiveArgument, directive.getSourceLocation(), message); } } } }
public static Optional<String> getDirectiveArgument(GraphQLObjectType parentType, String directiveName, String argumentName) { return Optional.ofNullable(parentType.getDefinition().getDirective(directiveName)) .map(d -> d.getArgument(argumentName)) .map(v -> (StringValue) v.getValue()) .map(StringValue::getValue); }
public Directive build() { Directive directive = new Directive(name, arguments, sourceLocation, comments, ignoredChars); return directive; } }
private Builder(Directive existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.arguments = existing.getArguments(); this.ignoredChars = existing.getIgnoredChars(); }
private GraphQLDirective[] buildDirectives(List<Directive> directives, List<Directive> extensionDirectives, DirectiveLocation directiveLocation, Set<GraphQLDirective> directiveDefinitions) { directives = directives == null ? emptyList() : directives; extensionDirectives = extensionDirectives == null ? emptyList() : extensionDirectives; Set<String> names = new LinkedHashSet<>(); List<GraphQLDirective> output = new ArrayList<>(); for (Directive directive : directives) { if (!names.contains(directive.getName())) { names.add(directive.getName()); output.add(schemaGeneratorHelper.buildDirective(directive, directiveDefinitions, directiveLocation)); } } for (Directive directive : extensionDirectives) { if (!names.contains(directive.getName())) { names.add(directive.getName()); output.add(schemaGeneratorHelper.buildDirective(directive, directiveDefinitions, directiveLocation)); } } return output.toArray(new GraphQLDirective[0]); }
private void checkEnumValues(List<GraphQLError> errors, EnumTypeDefinition enumType, List<EnumValueDefinition> enumValueDefinitions) { // enum unique ness checkNamedUniqueness(errors, enumValueDefinitions, EnumValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueNameError(enumType, inputValueDefinition)); // directive checks enumValueDefinitions.forEach(enumValue -> { BiFunction<String, Directive, NonUniqueDirectiveError> errorFunction = (directiveName, directive) -> new NonUniqueDirectiveError(enumType, enumValue, directiveName); checkNamedUniqueness(errors, enumValue.getDirectives(), Directive::getName, errorFunction); }); enumValueDefinitions.forEach(enumValue -> enumValue.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(enumType, enumValue)); BiFunction<String, Argument, NonUniqueArgumentError> errorFunction = (argumentName, argument) -> new NonUniqueArgumentError(enumType, enumValue, argumentName); checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, errorFunction); })); }
@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); } }
String iri = ((StringValue) field.getDirective("href").getArgument("iri").getValue()).getValue(); contextMap.put(field.getName(), iri); }); if (dir.getName().equals("service")) { String getQueryUri = typeUri + "_GET"; String getByIdQueryUri = typeUri + "_GET_BY_ID"; String serviceId = ((StringValue) dir.getArgument("id").getValue()).getValue(); rdfSchema.insertObjectTriple(typeUri, HGQL_HAS_FIELD, fieldURI); String serviceId = ((StringValue) field.getDirective("service").getArgument("id").getValue()).getValue(); String serviceURI = HGQL_SERVICE_NAMESPACE + serviceId; rdfSchema.insertObjectTriple(fieldURI, HGQL_HAS_SERVICE, serviceURI);
@Override public TraversalControl visitDirective(Directive node, TraverserContext<Node> context) { Directive changedNode = node.transform(builder -> { List<Argument> arguments = sort(node.getArguments(), comparing(Argument::getName)); builder.arguments(arguments); }); return changeNode(context, changedNode); }
@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 && (isNonNull(graphQLArgument.getType()))) { String message = String.format("Missing directive argument %s", graphQLArgument.getName()); addError(ValidationErrorType.MissingDirectiveArgument, directive.getSourceLocation(), message); } } } }
public static Optional<String> getDirectiveArgument(GraphQLFieldDefinition field, String directiveName, String argumentName) { return Optional.ofNullable(field.getDefinition().getDirective(directiveName)) .map(d -> d.getArgument(argumentName)) .map(v -> (StringValue) v.getValue()) .map(StringValue::getValue); } }