Skip to content

Commit 439e342

Browse files
authored
Merge pull request graphql-java#1529 from graphql-java/field-additional-data
add additional field data property
2 parents fccc0c7 + 84c7538 commit 439e342

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def getDevelopmentVersion() {
2020
println "git hash is empty: error: ${error.toString()}"
2121
throw new IllegalStateException("git hash could not be determined")
2222
}
23-
new SimpleDateFormat('yyyy-MM-dd\'T\'HH-mm-ss').format(new Date()) + "-" + gitHash
23+
def version = new SimpleDateFormat('yyyy-MM-dd\'T\'HH-mm-ss').format(new Date()) + "-" + gitHash
24+
println "created development version: $version"
25+
version
2426
}
2527

2628

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
import graphql.util.TraverserContext;
88

99
import java.util.ArrayList;
10+
import java.util.LinkedHashMap;
1011
import java.util.List;
12+
import java.util.Map;
1113
import java.util.function.Consumer;
1214

15+
import static graphql.Assert.assertNotNull;
16+
import static java.util.Collections.emptyMap;
17+
1318
/*
1419
* This is provided to a DataFetcher, therefore it is a public API.
1520
* This might change in the future.
@@ -22,11 +27,13 @@ public class Field extends AbstractNode<Field> implements Selection<Field>, Sele
2227
private final List<Argument> arguments;
2328
private final List<Directive> directives;
2429
private final SelectionSet selectionSet;
30+
private final Map<String, String> additionalData;
2531

2632
public static final String CHILD_ARGUMENTS = "arguments";
2733
public static final String CHILD_DIRECTIVES = "directives";
2834
public static final String CHILD_SELECTION_SET = "selectionSet";
2935

36+
3037
@Internal
3138
protected Field(String name,
3239
String alias,
@@ -35,13 +42,15 @@ protected Field(String name,
3542
SelectionSet selectionSet,
3643
SourceLocation sourceLocation,
3744
List<Comment> comments,
38-
IgnoredChars ignoredChars) {
45+
IgnoredChars ignoredChars,
46+
Map<String, String> additionalData) {
3947
super(sourceLocation, comments, ignoredChars);
4048
this.name = name;
4149
this.alias = alias;
4250
this.arguments = arguments;
4351
this.directives = directives;
4452
this.selectionSet = selectionSet;
53+
this.additionalData = new LinkedHashMap<>(additionalData);
4554
}
4655

4756

@@ -51,7 +60,7 @@ protected Field(String name,
5160
* @param name of the field
5261
*/
5362
public Field(String name) {
54-
this(name, null, new ArrayList<>(), new ArrayList<>(), null, null, new ArrayList<>(), IgnoredChars.EMPTY);
63+
this(name, null, new ArrayList<>(), new ArrayList<>(), null, null, new ArrayList<>(), IgnoredChars.EMPTY, emptyMap());
5564
}
5665

5766
/**
@@ -61,7 +70,7 @@ public Field(String name) {
6170
* @param arguments to the field
6271
*/
6372
public Field(String name, List<Argument> arguments) {
64-
this(name, null, arguments, new ArrayList<>(), null, null, new ArrayList<>(), IgnoredChars.EMPTY);
73+
this(name, null, arguments, new ArrayList<>(), null, null, new ArrayList<>(), IgnoredChars.EMPTY, emptyMap());
6574
}
6675

6776
/**
@@ -72,7 +81,7 @@ public Field(String name, List<Argument> arguments) {
7281
* @param selectionSet of the field
7382
*/
7483
public Field(String name, List<Argument> arguments, SelectionSet selectionSet) {
75-
this(name, null, arguments, new ArrayList<>(), selectionSet, null, new ArrayList<>(), IgnoredChars.EMPTY);
84+
this(name, null, arguments, new ArrayList<>(), selectionSet, null, new ArrayList<>(), IgnoredChars.EMPTY, emptyMap());
7685
}
7786

7887
/**
@@ -82,7 +91,7 @@ public Field(String name, List<Argument> arguments, SelectionSet selectionSet) {
8291
* @param selectionSet of the field
8392
*/
8493
public Field(String name, SelectionSet selectionSet) {
85-
this(name, null, new ArrayList<>(), new ArrayList<>(), selectionSet, null, new ArrayList<>(), IgnoredChars.EMPTY);
94+
this(name, null, new ArrayList<>(), new ArrayList<>(), selectionSet, null, new ArrayList<>(), IgnoredChars.EMPTY, emptyMap());
8695
}
8796

8897
@Override
@@ -137,6 +146,10 @@ public SelectionSet getSelectionSet() {
137146
return selectionSet;
138147
}
139148

149+
public Map<String, String> getAdditionalData() {
150+
return new LinkedHashMap<>(additionalData);
151+
}
152+
140153
@Override
141154
public boolean isEqualTo(Node o) {
142155
if (this == o) {
@@ -160,7 +173,8 @@ public Field deepCopy() {
160173
deepCopy(selectionSet),
161174
getSourceLocation(),
162175
getComments(),
163-
getIgnoredChars()
176+
getIgnoredChars(),
177+
additionalData
164178
);
165179
}
166180

@@ -207,6 +221,7 @@ public static final class Builder implements NodeBuilder {
207221
private List<Directive> directives = new ArrayList<>();
208222
private SelectionSet selectionSet;
209223
private IgnoredChars ignoredChars = IgnoredChars.EMPTY;
224+
private Map<String, String> additionalData = new LinkedHashMap<>();
210225

211226
private Builder() {
212227
}
@@ -220,6 +235,7 @@ private Builder(Field existing) {
220235
this.directives = existing.getDirectives();
221236
this.selectionSet = existing.getSelectionSet();
222237
this.ignoredChars = existing.getIgnoredChars();
238+
this.additionalData = existing.getAdditionalData();
223239
}
224240

225241

@@ -263,8 +279,19 @@ public Builder ignoredChars(IgnoredChars ignoredChars) {
263279
return this;
264280
}
265281

282+
public Builder additionalData(Map<String, String> additionalData) {
283+
this.additionalData = assertNotNull(additionalData);
284+
return this;
285+
}
286+
287+
public Builder additionalData(String key, String value) {
288+
this.additionalData.put(key, value);
289+
return this;
290+
}
291+
292+
266293
public Field build() {
267-
Field field = new Field(name, alias, arguments, directives, selectionSet, sourceLocation, comments, ignoredChars);
294+
Field field = new Field(name, alias, arguments, directives, selectionSet, sourceLocation, comments, ignoredChars, additionalData);
268295
return field;
269296
}
270297
}

0 commit comments

Comments
 (0)