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(); }
public DirectiveIllegalLocationError(DirectiveDefinition element, String locationName) { super(element, format("'%s' %s tried to use a location '%s' but that is illegal", element.getName(), BaseError.lineCol(element), locationName )); } }
public NonUniqueNameError(DirectiveDefinition typeDefinition, InputValueDefinition inputValueDefinition) { super(typeDefinition, format("The directive definition '%s' %s has declared an argument with a non unique name '%s'", typeDefinition.getName(), lineCol(typeDefinition), inputValueDefinition.getName())); }
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(); }
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); }; }
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(); }
public void remove(SDLDefinition definition) { assertNotNull("definition to remove can't be null"); if (definition instanceof ObjectTypeExtensionDefinition) { removeFromList(objectTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof InterfaceTypeExtensionDefinition) { removeFromList(interfaceTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof UnionTypeExtensionDefinition) { removeFromList(unionTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof EnumTypeExtensionDefinition) { removeFromList(enumTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof ScalarTypeExtensionDefinition) { removeFromList(scalarTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof InputObjectTypeExtensionDefinition) { removeFromList(inputObjectTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof ScalarTypeDefinition) { scalarTypes.remove(((ScalarTypeDefinition) definition).getName()); } else if (definition instanceof TypeDefinition) { types.remove(((TypeDefinition) definition).getName()); } else if (definition instanceof DirectiveDefinition) { directiveDefinitions.remove(((DirectiveDefinition) definition).getName()); } else if (definition instanceof SchemaDefinition) { schema = null; } else { Assert.assertShouldNeverHappen(); } }
return ((DirectiveDefinition) d).getName();
public DirectiveIllegalLocationError(DirectiveDefinition element, String locationName) { super(element, format("'%s' %s tried to use a location '%s' but that is illegal", element.getName(), BaseError.lineCol(element), locationName )); } }
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(); }
public NonUniqueNameError(DirectiveDefinition typeDefinition, InputValueDefinition inputValueDefinition) { super(typeDefinition, format("The directive definition '%s' %s has declared an argument with a non unique name '%s'", typeDefinition.getName(), lineCol(typeDefinition), inputValueDefinition.getName())); }
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(); }
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); }; }
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(); }
public void remove(SDLDefinition definition) { assertNotNull("definition to remove can't be null"); if (definition instanceof ObjectTypeExtensionDefinition) { removeFromList(objectTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof InterfaceTypeExtensionDefinition) { removeFromList(interfaceTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof UnionTypeExtensionDefinition) { removeFromList(unionTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof EnumTypeExtensionDefinition) { removeFromList(enumTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof ScalarTypeExtensionDefinition) { removeFromList(scalarTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof InputObjectTypeExtensionDefinition) { removeFromList(inputObjectTypeExtensions, (TypeDefinition) definition); } else if (definition instanceof ScalarTypeDefinition) { scalarTypes.remove(((ScalarTypeDefinition) definition).getName()); } else if (definition instanceof TypeDefinition) { types.remove(((TypeDefinition) definition).getName()); } else if (definition instanceof DirectiveDefinition) { directiveDefinitions.remove(((DirectiveDefinition) definition).getName()); } else if (definition instanceof SchemaDefinition) { schema = null; } else { Assert.assertShouldNeverHappen(); } }
return ((DirectiveDefinition) d).getName();