@Override public DirectiveDefinition deepCopy() { return new DirectiveDefinition(name, description, deepCopy(inputValueDefinitions), deepCopy(directiveLocations), getSourceLocation(), getComments(), getIgnoredChars()); }
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 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); }; }
public GraphQLDirective buildDirectiveFromDefinition(DirectiveDefinition directiveDefinition, Function<Type, GraphQLInputType> inputTypeFactory) { GraphQLDirective.Builder builder = GraphQLDirective.newDirective() .name(directiveDefinition.getName()) .description(buildDescription(directiveDefinition, directiveDefinition.getDescription())); List<DirectiveLocation> locations = buildLocations(directiveDefinition); locations.forEach(builder::validLocations); List<GraphQLArgument> arguments = directiveDefinition.getInputValueDefinitions().stream() .map(arg -> buildDirectiveArgumentFromDefinition(arg, inputTypeFactory)) .collect(Collectors.toList()); arguments.forEach(builder::argument); return builder.build(); }
@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 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()); }
public DirectiveDefinition build() { DirectiveDefinition directiveDefinition = new DirectiveDefinition(name, description, inputValueDefinitions, directiveLocations, sourceLocation, comments, ignoredChars); return directiveDefinition; } }
protected DirectiveDefinition createDirectiveDefinition(GraphqlParser.DirectiveDefinitionContext ctx) { DirectiveDefinition.Builder def = DirectiveDefinition.newDirectiveDefinition(); def.name(ctx.name().getText()); addCommonData(def, ctx); def.description(newDescription(ctx.description())); GraphqlParser.DirectiveLocationsContext directiveLocationsContext = ctx.directiveLocations(); List<DirectiveLocation> directiveLocations = new ArrayList<>(); while (directiveLocationsContext != null) { directiveLocations.add(0, createDirectiveLocation(directiveLocationsContext.directiveLocation())); directiveLocationsContext = directiveLocationsContext.directiveLocations(); } def.directiveLocations(directiveLocations); if (ctx.argumentsDefinition() != null) { def.inputValueDefinitions(createInputValueDefinitions(ctx.argumentsDefinition().inputValueDefinition())); } return def.build(); }
private void checkDirectiveArguments(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, Node element, String elementName, Directive directive, DirectiveDefinition directiveDefinition) { Map<String, InputValueDefinition> allowedArgs = getByName(directiveDefinition.getInputValueDefinitions(), (InputValueDefinition::getName), mergeFirst()); Map<String, Argument> providedArgs = getByName(directive.getArguments(), (Argument::getName), mergeFirst()); directive.getArguments().forEach(argument -> { InputValueDefinition allowedArg = allowedArgs.get(argument.getName()); if (allowedArg == null) { errors.add(new DirectiveUnknownArgumentError(element, elementName, directive.getName(), argument.getName())); } else { ArgValueOfAllowedTypeChecker argValueOfAllowedTypeChecker = new ArgValueOfAllowedTypeChecker(directive, element, elementName, argument, typeRegistry, runtimeWiring); argValueOfAllowedTypeChecker.checkArgValueMatchesAllowedType(errors, argument.getValue(), allowedArg.getType()); } }); allowedArgs.forEach((argName, definitionArgument) -> { if (isNoNullArgWithoutDefaultValue(definitionArgument)) { if (!providedArgs.containsKey(argName)) { errors.add(new DirectiveMissingNonNullArgumentError(element, elementName, directive.getName(), argName)); } } }); }
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)); } }); }); }
public GraphQLDirective buildDirectiveFromDefinition(DirectiveDefinition directiveDefinition, Function<Type, GraphQLInputType> inputTypeFactory) { GraphQLDirective.Builder builder = GraphQLDirective.newDirective() .name(directiveDefinition.getName()) .description(buildDescription(directiveDefinition, directiveDefinition.getDescription())); List<DirectiveLocation> locations = buildLocations(directiveDefinition); locations.forEach(builder::validLocations); List<GraphQLArgument> arguments = directiveDefinition.getInputValueDefinitions().stream() .map(arg -> buildDirectiveArgumentFromDefinition(arg, inputTypeFactory)) .collect(Collectors.toList()); arguments.forEach(builder::argument); return builder.build(); }
@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 <T extends DirectiveDefinition> Optional<GraphQLError> define(Map<String, T> source, Map<String, T> target, T newEntry) { String name = newEntry.getName(); T olderEntry = source.get(name); if (olderEntry != null) { return Optional.of(handleReDefinition(olderEntry, newEntry)); } else { target.put(name, newEntry); } return Optional.empty(); }
private List<DirectiveLocation> buildLocations(DirectiveDefinition directiveDefinition) { return directiveDefinition.getDirectiveLocations().stream() .map(dl -> DirectiveLocation.valueOf(dl.getName().toUpperCase())) .collect(Collectors.toList()); }
public DirectiveDefinition build() { DirectiveDefinition directiveDefinition = new DirectiveDefinition(name, description, inputValueDefinitions, directiveLocations, sourceLocation, comments, ignoredChars); return directiveDefinition; } }
protected DirectiveDefinition createDirectiveDefinition(GraphqlParser.DirectiveDefinitionContext ctx) { DirectiveDefinition.Builder def = DirectiveDefinition.newDirectiveDefinition(); def.name(ctx.name().getText()); addCommonData(def, ctx); def.description(newDescription(ctx.description())); GraphqlParser.DirectiveLocationsContext directiveLocationsContext = ctx.directiveLocations(); List<DirectiveLocation> directiveLocations = new ArrayList<>(); while (directiveLocationsContext != null) { directiveLocations.add(0, createDirectiveLocation(directiveLocationsContext.directiveLocation())); directiveLocationsContext = directiveLocationsContext.directiveLocations(); } def.directiveLocations(directiveLocations); if (ctx.argumentsDefinition() != null) { def.inputValueDefinitions(createInputValueDefinitions(ctx.argumentsDefinition().inputValueDefinition())); } return def.build(); }
private void checkDirectiveArguments(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, Node element, String elementName, Directive directive, DirectiveDefinition directiveDefinition) { Map<String, InputValueDefinition> allowedArgs = getByName(directiveDefinition.getInputValueDefinitions(), (InputValueDefinition::getName), mergeFirst()); Map<String, Argument> providedArgs = getByName(directive.getArguments(), (Argument::getName), mergeFirst()); directive.getArguments().forEach(argument -> { InputValueDefinition allowedArg = allowedArgs.get(argument.getName()); if (allowedArg == null) { errors.add(new DirectiveUnknownArgumentError(element, elementName, directive.getName(), argument.getName())); } else { ArgValueOfAllowedTypeChecker argValueOfAllowedTypeChecker = new ArgValueOfAllowedTypeChecker(directive, element, elementName, argument, typeRegistry, runtimeWiring); argValueOfAllowedTypeChecker.checkArgValueMatchesAllowedType(errors, argument.getValue(), allowedArg.getType()); } }); allowedArgs.forEach((argName, definitionArgument) -> { if (isNoNullArgWithoutDefaultValue(definitionArgument)) { if (!providedArgs.containsKey(argName)) { errors.add(new DirectiveMissingNonNullArgumentError(element, elementName, directive.getName(), argName)); } } }); }
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(); }
@Override public DirectiveDefinition deepCopy() { return new DirectiveDefinition(name, description, deepCopy(inputValueDefinitions), deepCopy(directiveLocations), getSourceLocation(), getComments(), getIgnoredChars()); }