Skip to content

Commit bfee885

Browse files
authored
Merge pull request graphql-java#1143 from graphql-java/ast-mutable-again
makes ast nodes mutable again for now
2 parents 5ea18ff + c6ee073 commit bfee885

11 files changed

Lines changed: 85 additions & 34 deletions

src/main/java/graphql/language/Argument.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
@PublicApi
1414
public class Argument extends AbstractNode<Argument> implements NamedNode<Argument> {
1515

16-
private final String name;
17-
private final Value value;
16+
private String name;
17+
private Value value;
1818

1919
@Internal
2020
protected Argument(String name, Value value, SourceLocation sourceLocation, List<Comment> comments) {
@@ -42,6 +42,14 @@ public Value getValue() {
4242
return value;
4343
}
4444

45+
public void setName(String name) {
46+
this.name = name;
47+
}
48+
49+
public void setValue(Value value) {
50+
this.value = value;
51+
}
52+
4553
@Override
4654
public List<Node> getChildren() {
4755
List<Node> result = new ArrayList<>();

src/main/java/graphql/language/ArrayValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public ArrayValue(List<Value> values) {
3232
}
3333

3434
public List<Value> getValues() {
35-
return new ArrayList<>(values);
35+
return values;
3636
}
3737

3838
@Override

src/main/java/graphql/language/Document.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Document(List<Definition> definitions) {
2929
}
3030

3131
public List<Definition> getDefinitions() {
32-
return new ArrayList<>(definitions);
32+
return definitions;
3333
}
3434

3535

src/main/java/graphql/language/EnumValueDefinition.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33

44
import graphql.Internal;
5+
import graphql.PublicApi;
56
import graphql.util.TraversalControl;
67
import graphql.util.TraverserContext;
78

89
import java.util.ArrayList;
910
import java.util.List;
1011
import java.util.function.Consumer;
1112

13+
@PublicApi
1214
public class EnumValueDefinition extends AbstractNode<EnumValueDefinition> implements DirectivesContainer<EnumValueDefinition> {
1315
private final String name;
1416
private final Description description;
@@ -17,10 +19,10 @@ public class EnumValueDefinition extends AbstractNode<EnumValueDefinition> imple
1719

1820
@Internal
1921
protected EnumValueDefinition(String name,
20-
List<Directive> directives,
21-
Description description,
22-
SourceLocation sourceLocation,
23-
List<Comment> comments) {
22+
List<Directive> directives,
23+
Description description,
24+
SourceLocation sourceLocation,
25+
List<Comment> comments) {
2426
super(sourceLocation, comments);
2527
this.name = name;
2628
this.description = description;

src/main/java/graphql/language/Field.java

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717
@PublicApi
1818
public class Field extends AbstractNode<Field> implements Selection<Field>, SelectionSetContainer<Field>, DirectivesContainer<Field> {
1919

20-
private final String name;
21-
private final String alias;
22-
private final List<Argument> arguments;
23-
private final List<Directive> directives;
24-
private final SelectionSet selectionSet;
20+
private String name;
21+
private String alias;
22+
private List<Argument> arguments;
23+
private List<Directive> directives;
24+
private SelectionSet selectionSet;
2525

2626
@Internal
2727
protected Field(String name,
28-
String alias,
29-
List<Argument> arguments,
30-
List<Directive> directives,
31-
SelectionSet selectionSet,
32-
SourceLocation sourceLocation,
33-
List<Comment> comments) {
28+
String alias,
29+
List<Argument> arguments,
30+
List<Directive> directives,
31+
SelectionSet selectionSet,
32+
SourceLocation sourceLocation,
33+
List<Comment> comments) {
3434
super(sourceLocation, comments);
3535
this.name = name;
3636
this.alias = alias;
@@ -49,7 +49,6 @@ public Field(String name) {
4949

5050
/**
5151
* alternative to using a Builder for convenience
52-
*
5352
*/
5453
public Field(String name, List<Argument> arguments) {
5554
this(name, null, arguments, new ArrayList<>(), null, null, new ArrayList<>());
@@ -74,7 +73,9 @@ public List<Node> getChildren() {
7473
List<Node> result = new ArrayList<>();
7574
result.addAll(arguments);
7675
result.addAll(directives);
77-
if (selectionSet != null) result.add(selectionSet);
76+
if (selectionSet != null) {
77+
result.add(selectionSet);
78+
}
7879
return result;
7980
}
8081

@@ -89,7 +90,15 @@ public String getAlias() {
8990
}
9091

9192
public List<Argument> getArguments() {
92-
return new ArrayList<>(arguments);
93+
return arguments;
94+
}
95+
96+
public void setArguments(List<Argument> arguments) {
97+
this.arguments = arguments;
98+
}
99+
100+
public void setDirectives(List<Directive> directives) {
101+
this.directives = directives;
93102
}
94103

95104
@Override
@@ -102,10 +111,26 @@ public SelectionSet getSelectionSet() {
102111
return selectionSet;
103112
}
104113

114+
public void setName(String name) {
115+
this.name = name;
116+
}
117+
118+
public void setAlias(String alias) {
119+
this.alias = alias;
120+
}
121+
122+
public void setSelectionSet(SelectionSet selectionSet) {
123+
this.selectionSet = selectionSet;
124+
}
125+
105126
@Override
106127
public boolean isEqualTo(Node o) {
107-
if (this == o) return true;
108-
if (o == null || getClass() != o.getClass()) return false;
128+
if (this == o) {
129+
return true;
130+
}
131+
if (o == null || getClass() != o.getClass()) {
132+
return false;
133+
}
109134

110135
Field that = (Field) o;
111136

src/main/java/graphql/language/FieldDefinition.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
@PublicApi
1414
public class FieldDefinition extends AbstractNode<FieldDefinition> implements DirectivesContainer<FieldDefinition> {
15-
private final String name;
16-
private final Type type;
15+
private String name;
16+
private Type type;
1717
private final Description description;
1818
private final List<InputValueDefinition> inputValueDefinitions;
1919
private final List<Directive> directives;
@@ -53,7 +53,7 @@ public Description getDescription() {
5353
}
5454

5555
public List<InputValueDefinition> getInputValueDefinitions() {
56-
return new ArrayList<>(inputValueDefinitions);
56+
return inputValueDefinitions;
5757
}
5858

5959
@Override
@@ -92,6 +92,14 @@ public FieldDefinition deepCopy() {
9292
);
9393
}
9494

95+
public void setName(String name) {
96+
this.name = name;
97+
}
98+
99+
public void setType(Type type) {
100+
this.type = type;
101+
}
102+
95103
@Override
96104
public String toString() {
97105
return "FieldDefinition{" +

src/main/java/graphql/language/InputObjectTypeDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public List<Directive> getDirectives() {
3838
}
3939

4040
public List<InputValueDefinition> getInputValueDefinitions() {
41-
return new ArrayList<>(inputValueDefinitions);
41+
return inputValueDefinitions;
4242
}
4343

4444
@Override

src/main/java/graphql/language/ObjectTypeDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public List<Directive> getDirectives() {
5151
}
5252

5353
public List<FieldDefinition> getFieldDefinitions() {
54-
return new ArrayList<>(fieldDefinitions);
54+
return fieldDefinitions;
5555
}
5656

5757
@Override

src/main/java/graphql/language/OperationDefinition.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public enum Operation {
1919

2020
private final String name;
2121

22-
private final Operation operation;
22+
private Operation operation;
2323
private final List<VariableDefinition> variableDefinitions;
2424
private final List<Directive> directives;
25-
private final SelectionSet selectionSet;
25+
private SelectionSet selectionSet;
2626

2727
@Internal
2828
protected OperationDefinition(String name,
@@ -67,13 +67,21 @@ public Operation getOperation() {
6767
}
6868

6969
public List<VariableDefinition> getVariableDefinitions() {
70-
return new ArrayList<>(variableDefinitions);
70+
return variableDefinitions;
7171
}
7272

7373
public List<Directive> getDirectives() {
7474
return new ArrayList<>(directives);
7575
}
7676

77+
public void setOperation(Operation operation) {
78+
this.operation = operation;
79+
}
80+
81+
public void setSelectionSet(SelectionSet selectionSet) {
82+
this.selectionSet = selectionSet;
83+
}
84+
7785
@Override
7886
public SelectionSet getSelectionSet() {
7987
return selectionSet;

src/main/java/graphql/language/SchemaDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Directive getDirective(String directiveName) {
4343

4444

4545
public List<OperationTypeDefinition> getOperationTypeDefinitions() {
46-
return new ArrayList<>(operationTypeDefinitions);
46+
return operationTypeDefinitions;
4747
}
4848

4949
@Override

0 commit comments

Comments
 (0)