|
| 1 | +package graphql.language; |
| 2 | + |
| 3 | +import graphql.PublicApi; |
| 4 | + |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.LinkedHashMap; |
| 7 | +import java.util.List; |
| 8 | +import java.util.Map; |
| 9 | +import java.util.function.Consumer; |
| 10 | + |
| 11 | +import static graphql.Assert.assertNotNull; |
| 12 | + |
| 13 | +@PublicApi |
| 14 | +public class SchemaExtensionDefinition extends SchemaDefinition { |
| 15 | + |
| 16 | + protected SchemaExtensionDefinition(List<Directive> directives, List<OperationTypeDefinition> operationTypeDefinitions, SourceLocation sourceLocation, List<Comment> comments, IgnoredChars ignoredChars, Map<String, String> additionalData) { |
| 17 | + super(directives, operationTypeDefinitions, sourceLocation, comments, ignoredChars, additionalData); |
| 18 | + } |
| 19 | + |
| 20 | + @Override |
| 21 | + public SchemaExtensionDefinition withNewChildren(NodeChildrenContainer newChildren) { |
| 22 | + return transformExtension(builder -> builder |
| 23 | + .directives(newChildren.getChildren(CHILD_DIRECTIVES)) |
| 24 | + .operationTypeDefinitions(newChildren.getChildren(CHILD_OPERATION_TYPE_DEFINITIONS)) |
| 25 | + ); |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public SchemaExtensionDefinition deepCopy() { |
| 30 | + return new SchemaExtensionDefinition(deepCopy(getDirectives()), deepCopy(getOperationTypeDefinitions()), getSourceLocation(), getComments(), |
| 31 | + getIgnoredChars(), getAdditionalData()); |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public String toString() { |
| 36 | + return "SchemaExtensionDefinition{" + |
| 37 | + "directives=" + getDirectives() + |
| 38 | + ", operationTypeDefinitions=" + getOperationTypeDefinitions() + |
| 39 | + "}"; |
| 40 | + } |
| 41 | + |
| 42 | + public SchemaExtensionDefinition transformExtension(Consumer<Builder> builderConsumer) { |
| 43 | + Builder builder = new Builder(this); |
| 44 | + builderConsumer.accept(builder); |
| 45 | + return builder.build(); |
| 46 | + } |
| 47 | + |
| 48 | + public static Builder newSchemaExtensionDefinition() { |
| 49 | + return new Builder(); |
| 50 | + } |
| 51 | + |
| 52 | + public static final class Builder implements NodeBuilder { |
| 53 | + private SourceLocation sourceLocation; |
| 54 | + private List<Comment> comments = new ArrayList<>(); |
| 55 | + private List<Directive> directives = new ArrayList<>(); |
| 56 | + private List<OperationTypeDefinition> operationTypeDefinitions = new ArrayList<>(); |
| 57 | + private IgnoredChars ignoredChars = IgnoredChars.EMPTY; |
| 58 | + private Map<String, String> additionalData = new LinkedHashMap<>(); |
| 59 | + |
| 60 | + protected Builder() { |
| 61 | + } |
| 62 | + |
| 63 | + protected Builder(SchemaDefinition existing) { |
| 64 | + this.sourceLocation = existing.getSourceLocation(); |
| 65 | + this.comments = existing.getComments(); |
| 66 | + this.directives = existing.getDirectives(); |
| 67 | + this.operationTypeDefinitions = existing.getOperationTypeDefinitions(); |
| 68 | + this.ignoredChars = existing.getIgnoredChars(); |
| 69 | + this.additionalData = new LinkedHashMap<>(existing.getAdditionalData()); |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + public Builder sourceLocation(SourceLocation sourceLocation) { |
| 74 | + this.sourceLocation = sourceLocation; |
| 75 | + return this; |
| 76 | + } |
| 77 | + |
| 78 | + public Builder comments(List<Comment> comments) { |
| 79 | + this.comments = comments; |
| 80 | + return this; |
| 81 | + } |
| 82 | + |
| 83 | + public Builder directives(List<Directive> directives) { |
| 84 | + this.directives = directives; |
| 85 | + return this; |
| 86 | + } |
| 87 | + |
| 88 | + public Builder directive(Directive directive) { |
| 89 | + this.directives.add(directive); |
| 90 | + return this; |
| 91 | + } |
| 92 | + |
| 93 | + public Builder operationTypeDefinitions(List<OperationTypeDefinition> operationTypeDefinitions) { |
| 94 | + this.operationTypeDefinitions = operationTypeDefinitions; |
| 95 | + return this; |
| 96 | + } |
| 97 | + |
| 98 | + public Builder operationTypeDefinition(OperationTypeDefinition operationTypeDefinitions) { |
| 99 | + this.operationTypeDefinitions.add(operationTypeDefinitions); |
| 100 | + return this; |
| 101 | + } |
| 102 | + |
| 103 | + public Builder ignoredChars(IgnoredChars ignoredChars) { |
| 104 | + this.ignoredChars = ignoredChars; |
| 105 | + return this; |
| 106 | + } |
| 107 | + |
| 108 | + public Builder additionalData(Map<String, String> additionalData) { |
| 109 | + this.additionalData = assertNotNull(additionalData); |
| 110 | + return this; |
| 111 | + } |
| 112 | + |
| 113 | + public Builder additionalData(String key, String value) { |
| 114 | + this.additionalData.put(key, value); |
| 115 | + return this; |
| 116 | + } |
| 117 | + |
| 118 | + public SchemaExtensionDefinition build() { |
| 119 | + return new SchemaExtensionDefinition(directives, |
| 120 | + operationTypeDefinitions, |
| 121 | + sourceLocation, |
| 122 | + comments, |
| 123 | + ignoredChars, |
| 124 | + additionalData); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | +} |
0 commit comments