Skip to content

Commit 4a899b3

Browse files
committed
reaming Graphql classes to GraphQL ... WIP
1 parent 4b6c8aa commit 4a899b3

8 files changed

+79
-77
lines changed

src/main/java/graphql/execution/batched/BatchedExecutionStrategy.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ public class BatchedExecutionStrategy extends ExecutionStrategy {
3131

3232
@Override
3333
public ExecutionResult execute(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, Map<String, List<Field>> fields) {
34-
return execute(executionContext, new GraphqlExecutionNode(parentType, fields,
35-
Collections.singletonList(new GraphqlExecutionNodeDatum(new LinkedHashMap<String, Object>(), source))));
34+
return execute(executionContext, new GraphqlExecutionNode2(parentType, fields,
35+
Collections.singletonList(new GraphqlExecutionNodeDatum22(new LinkedHashMap<String, Object>(), source))));
3636
}
3737

38-
private ExecutionResult execute(ExecutionContext executionContext, GraphqlExecutionNode root) {
38+
private ExecutionResult execute(ExecutionContext executionContext, GraphqlExecutionNode2 root) {
3939

40-
Queue<GraphqlExecutionNode> nodes = new ArrayDeque<>();
40+
Queue<GraphqlExecutionNode2> nodes = new ArrayDeque<>();
4141
nodes.add(root);
4242

4343
while (!nodes.isEmpty()) {
4444

45-
GraphqlExecutionNode node = nodes.poll();
45+
GraphqlExecutionNode2 node = nodes.poll();
4646

4747
for (String fieldName : node.getFields().keySet()) {
4848
List<Field> fieldList = node.getFields().get(fieldName);
49-
List<GraphqlExecutionNode> childNodes = resolveField(executionContext, node.getParentType(),
49+
List<GraphqlExecutionNode2> childNodes = resolveField(executionContext, node.getParentType(),
5050
node.getData(), fieldName, fieldList);
5151
nodes.addAll(childNodes);
5252
}
@@ -55,31 +55,31 @@ private ExecutionResult execute(ExecutionContext executionContext, GraphqlExecut
5555

5656
}
5757

58-
private GraphqlExecutionNodeDatum getOnlyElement(List<GraphqlExecutionNodeDatum> list) {
58+
private GraphqlExecutionNodeDatum22 getOnlyElement(List<GraphqlExecutionNodeDatum22> list) {
5959
return list.get(0);
6060
}
6161

6262
// Use the data.source objects to fetch
6363
// Use the data.parentResult objects to put values into. These are either primatives or empty maps
6464
// If they were empty maps, we need that list of nodes to process
6565

66-
private List<GraphqlExecutionNode> resolveField(ExecutionContext executionContext, GraphQLObjectType parentType,
67-
List<GraphqlExecutionNodeDatum> nodeData, String fieldName, List<Field> fields) {
66+
private List<GraphqlExecutionNode2> resolveField(ExecutionContext executionContext, GraphQLObjectType parentType,
67+
List<GraphqlExecutionNodeDatum22> nodeData, String fieldName, List<Field> fields) {
6868

6969
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0));
7070
if (fieldDef == null) {
7171
return Collections.emptyList();
7272
}
73-
List<GraphExecutionNodeValue> values = fetchData(executionContext, parentType, nodeData, fields, fieldDef);
73+
List<GraphQLExecutionNodeValue> values = fetchData(executionContext, parentType, nodeData, fields, fieldDef);
7474

7575
return completeValues(executionContext, parentType, values, fieldName, fields, fieldDef.getType());
7676
}
7777

7878
/**
7979
* Updates parents and returns new Nodes.
8080
*/
81-
private List<GraphqlExecutionNode> completeValues(ExecutionContext executionContext, GraphQLObjectType parentType,
82-
List<GraphExecutionNodeValue> values, String fieldName, List<Field> fields,
81+
private List<GraphqlExecutionNode2> completeValues(ExecutionContext executionContext, GraphQLObjectType parentType,
82+
List<GraphQLExecutionNodeValue> values, String fieldName, List<Field> fields,
8383
GraphQLOutputType outputType) {
8484

8585
GraphQLType fieldType = handleNonNullType(outputType, values, parentType, fields);
@@ -97,20 +97,20 @@ private List<GraphqlExecutionNode> completeValues(ExecutionContext executionCont
9797
}
9898

9999
@SuppressWarnings("unchecked")
100-
private List<GraphqlExecutionNode> handleList(ExecutionContext executionContext,
101-
List<GraphExecutionNodeValue> values, String fieldName, List<Field> fields,
100+
private List<GraphqlExecutionNode2> handleList(ExecutionContext executionContext,
101+
List<GraphQLExecutionNodeValue> values, String fieldName, List<Field> fields,
102102
GraphQLObjectType parentType, GraphQLList listType) {
103103

104-
List<GraphExecutionNodeValue> flattenedNodeValues = new ArrayList<>();
104+
List<GraphQLExecutionNodeValue> flattenedNodeValues = new ArrayList<>();
105105

106-
for (GraphExecutionNodeValue value: values) {
106+
for (GraphQLExecutionNodeValue value: values) {
107107
if (value.getValue() == null) {
108108
value.getResultContainer().putResult(fieldName, null);
109109
} else {
110-
GraphqlExecutionResultList flattenedDatum = value.getResultContainer().createAndPutEmptyChildList(
110+
GraphqlExecutionResultList2 flattenedDatum = value.getResultContainer().createAndPutEmptyChildList(
111111
fieldName);
112112
for (Object rawValue : (List<Object>) value.getValue()) {
113-
flattenedNodeValues.add(new GraphExecutionNodeValue(flattenedDatum, rawValue));
113+
flattenedNodeValues.add(new GraphQLExecutionNodeValue(flattenedDatum, rawValue));
114114
}
115115
}
116116
}
@@ -120,49 +120,49 @@ private List<GraphqlExecutionNode> handleList(ExecutionContext executionContext,
120120

121121
}
122122

123-
private List<GraphqlExecutionNode> handleObject(ExecutionContext executionContext,
124-
List<GraphExecutionNodeValue> values, String fieldName, List<Field> fields, GraphQLType fieldType) {
123+
private List<GraphqlExecutionNode2> handleObject(ExecutionContext executionContext,
124+
List<GraphQLExecutionNodeValue> values, String fieldName, List<Field> fields, GraphQLType fieldType) {
125125

126126
ChildDataCollector collector = createAndPopulateChildData(values, fieldName, fieldType);
127127

128-
List<GraphqlExecutionNode> childNodes =
128+
List<GraphqlExecutionNode2> childNodes =
129129
createChildNodes(executionContext, fields, collector);
130130

131131
return childNodes;
132132
}
133133

134-
private List<GraphqlExecutionNode> createChildNodes(ExecutionContext executionContext, List<Field> fields,
134+
private List<GraphqlExecutionNode2> createChildNodes(ExecutionContext executionContext, List<Field> fields,
135135
ChildDataCollector collector) {
136136

137-
List<GraphqlExecutionNode> childNodes = new ArrayList<>();
137+
List<GraphqlExecutionNode2> childNodes = new ArrayList<>();
138138

139139
for (ChildDataCollector.Entry entry: collector.getEntries()) {
140140
Map<String, List<Field>> childFields = getChildFields(executionContext, entry.getObjectType(), fields);
141-
childNodes.add(new GraphqlExecutionNode(entry.getObjectType(), childFields, entry.getData()));
141+
childNodes.add(new GraphqlExecutionNode2(entry.getObjectType(), childFields, entry.getData()));
142142
}
143143
return childNodes;
144144
}
145145

146-
private ChildDataCollector createAndPopulateChildData(List<GraphExecutionNodeValue> values, String fieldName,
146+
private ChildDataCollector createAndPopulateChildData(List<GraphQLExecutionNodeValue> values, String fieldName,
147147
GraphQLType fieldType) {
148148
ChildDataCollector collector = new ChildDataCollector();
149-
for (GraphExecutionNodeValue value: values) {
149+
for (GraphQLExecutionNodeValue value: values) {
150150
if (value.getValue() == null) {
151151
// We hit a null, insert the null and do not create a child
152152
value.getResultContainer().putResult(fieldName, null);
153153
} else {
154-
GraphqlExecutionNodeDatum childDatum = value.getResultContainer().createAndPutChildDatum(fieldName, value.getValue());
154+
GraphqlExecutionNodeDatum22 childDatum = value.getResultContainer().createAndPutChildDatum(fieldName, value.getValue());
155155
GraphQLObjectType graphQLObjectType = getGraphQLObjectType(fieldType, value.getValue());
156156
collector.putChildData(graphQLObjectType, childDatum);
157157
}
158158
}
159159
return collector;
160160
}
161161

162-
private GraphQLType handleNonNullType(GraphQLType fieldType, List<GraphExecutionNodeValue> values,
162+
private GraphQLType handleNonNullType(GraphQLType fieldType, List<GraphQLExecutionNodeValue> values,
163163
/*Nullable*/ GraphQLObjectType parentType, /*Nullable*/ List<Field> fields) {
164164
if (isNonNull(fieldType)) {
165-
for (GraphExecutionNodeValue value: values) {
165+
for (GraphQLExecutionNodeValue value: values) {
166166
if (value.getValue() == null) {
167167
throw new GraphQLException("Found null value for non-null type with parent: '"
168168
+ parentType.getName() + "' for fields: " + fields);
@@ -203,9 +203,9 @@ private GraphQLObjectType getGraphQLObjectType(GraphQLType fieldType, Object val
203203
return resolvedType;
204204
}
205205

206-
private void handlePrimitives(List<GraphExecutionNodeValue> values, String fieldName,
206+
private void handlePrimitives(List<GraphQLExecutionNodeValue> values, String fieldName,
207207
GraphQLType type) {
208-
for (GraphExecutionNodeValue value : values) {
208+
for (GraphQLExecutionNodeValue value : values) {
209209
Object coercedValue = coerce(type, value.getValue());
210210
value.getResultContainer().putResult(fieldName, coercedValue);
211211
}
@@ -234,13 +234,13 @@ private boolean isObject(GraphQLType type) {
234234
}
235235

236236
@SuppressWarnings("unchecked")
237-
private List<GraphExecutionNodeValue> fetchData(ExecutionContext executionContext, GraphQLObjectType parentType,
238-
List<GraphqlExecutionNodeDatum> nodeData, List<Field> fields, GraphQLFieldDefinition fieldDef) {
237+
private List<GraphQLExecutionNodeValue> fetchData(ExecutionContext executionContext, GraphQLObjectType parentType,
238+
List<GraphqlExecutionNodeDatum22> nodeData, List<Field> fields, GraphQLFieldDefinition fieldDef) {
239239

240240
Map<String, Object> argumentValues = valuesResolver.getArgumentValues(
241241
fieldDef.getArguments(), fields.get(0).getArguments(), executionContext.getVariables());
242242
List<Object> sources = new ArrayList<>();
243-
for (GraphqlExecutionNodeDatum n: nodeData) {
243+
for (GraphqlExecutionNodeDatum22 n: nodeData) {
244244
sources.add(n.getSource());
245245
}
246246
DataFetchingEnvironment environment = new DataFetchingEnvironment(
@@ -266,9 +266,9 @@ private List<GraphExecutionNodeValue> fetchData(ExecutionContext executionContex
266266
}
267267
assert nodeData.size() == values.size();
268268

269-
List<GraphExecutionNodeValue> retVal = new ArrayList<>();
269+
List<GraphQLExecutionNodeValue> retVal = new ArrayList<>();
270270
for (int i = 0; i < nodeData.size(); i++) {
271-
retVal.add(new GraphExecutionNodeValue(nodeData.get(i), values.get(i)));
271+
retVal.add(new GraphQLExecutionNodeValue(nodeData.get(i), values.get(i)));
272272
}
273273
return retVal;
274274
}

src/main/java/graphql/execution/batched/ChildDataCollector.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package graphql.execution.batched;
22

33
import graphql.schema.GraphQLObjectType;
4+
45
import java.util.ArrayList;
56
import java.util.HashMap;
67
import java.util.List;
78
import java.util.Map;
89

910
public class ChildDataCollector {
1011

11-
private final Map<String, List<GraphqlExecutionNodeDatum>> childDataByTypename = new HashMap<>();
12+
private final Map<String, List<GraphqlExecutionNodeDatum22>> childDataByTypename = new HashMap<>();
1213
private final Map<String, GraphQLObjectType> childTypesByName = new HashMap<>();
1314

1415

15-
public void putChildData(GraphQLObjectType objectType, GraphqlExecutionNodeDatum datum) {
16+
public void putChildData(GraphQLObjectType objectType, GraphqlExecutionNodeDatum22 datum) {
1617
childTypesByName.put(objectType.getName(), objectType);
1718
multimapPut(childDataByTypename, objectType.getName(), datum);
1819
}
@@ -37,18 +38,18 @@ public List<Entry> getEntries() {
3738
List<Entry> entries = new ArrayList<>();
3839
for (String childTypename: childTypesByName.keySet()) {
3940
GraphQLObjectType childType = childTypesByName.get(childTypename);
40-
List<GraphqlExecutionNodeDatum> childData = multimapGet(childDataByTypename, childTypename);
41+
List<GraphqlExecutionNodeDatum22> childData = multimapGet(childDataByTypename, childTypename);
4142
entries.add(new Entry(childType, childData));
4243
}
4344
return entries;
4445
}
4546

4647
public static class Entry {
4748
private final GraphQLObjectType objectType;
48-
private final List<GraphqlExecutionNodeDatum> data;
49+
private final List<GraphqlExecutionNodeDatum22> data;
4950

5051
public Entry(GraphQLObjectType objectType,
51-
List<GraphqlExecutionNodeDatum> data) {
52+
List<GraphqlExecutionNodeDatum22> data) {
5253
this.objectType = objectType;
5354
this.data = data;
5455
}
@@ -57,7 +58,7 @@ public GraphQLObjectType getObjectType() {
5758
return objectType;
5859
}
5960

60-
public List<GraphqlExecutionNodeDatum> getData() {
61+
public List<GraphqlExecutionNodeDatum22> getData() {
6162
return data;
6263
}
6364
}

src/main/java/graphql/execution/batched/GraphExecutionNodeValue.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package graphql.execution.batched;
2+
3+
public class GraphQLExecutionNodeValue {
4+
5+
private final GraphqlExecutionResultContainer2 resultContainer;
6+
private final Object value;
7+
8+
public GraphQLExecutionNodeValue(GraphqlExecutionResultContainer2 resultContainer, /*Nullable*/ Object value) {
9+
this.resultContainer = resultContainer;
10+
this.value = value;
11+
}
12+
13+
public GraphqlExecutionResultContainer2 getResultContainer() {
14+
return resultContainer;
15+
}
16+
17+
/*Nullable*/ public Object getValue() {
18+
return value;
19+
}
20+
}

src/main/java/graphql/execution/batched/GraphqlExecutionNode.java renamed to src/main/java/graphql/execution/batched/GraphqlExecutionNode2.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import graphql.language.Field;
44
import graphql.schema.GraphQLObjectType;
5+
56
import java.util.List;
67
import java.util.Map;
78

8-
class GraphqlExecutionNode {
9+
class GraphqlExecutionNode2 {
910

1011
private final GraphQLObjectType parentType;
1112
private final Map<String, List<Field>> fields;
12-
private final List<GraphqlExecutionNodeDatum> data;
13+
private final List<GraphqlExecutionNodeDatum22> data;
1314

14-
public GraphqlExecutionNode(GraphQLObjectType parentType,
15-
Map<String, List<Field>> fields,
16-
List<GraphqlExecutionNodeDatum> data) {
15+
public GraphqlExecutionNode2(GraphQLObjectType parentType,
16+
Map<String, List<Field>> fields,
17+
List<GraphqlExecutionNodeDatum22> data) {
1718
this.parentType = parentType;
1819
this.fields = fields;
1920
this.data = data;
@@ -27,7 +28,7 @@ public Map<String, List<Field>> getFields() {
2728
return fields;
2829
}
2930

30-
public List<GraphqlExecutionNodeDatum> getData() {
31+
public List<GraphqlExecutionNodeDatum22> getData() {
3132
return data;
3233
}
3334
}

src/main/java/graphql/execution/batched/GraphqlExecutionNodeDatum.java renamed to src/main/java/graphql/execution/batched/GraphqlExecutionNodeDatum22.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import java.util.Map;
44

5-
class GraphqlExecutionNodeDatum extends GraphqlExecutionResultContainer {
5+
class GraphqlExecutionNodeDatum22 extends GraphqlExecutionResultContainer2 {
66
private final Map<String, Object> parentResult;
77
private final Object source;
88

9-
public GraphqlExecutionNodeDatum(Map<String, Object> parentResult, Object source) {
9+
public GraphqlExecutionNodeDatum22(Map<String, Object> parentResult, Object source) {
1010
this.parentResult = parentResult;
1111
this.source = source;
1212
}

src/main/java/graphql/execution/batched/GraphqlExecutionResultContainer.java renamed to src/main/java/graphql/execution/batched/GraphqlExecutionResultContainer2.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
import java.util.List;
66
import java.util.Map;
77

8-
public abstract class GraphqlExecutionResultContainer {
8+
public abstract class GraphqlExecutionResultContainer2 {
99

1010
/**
1111
* Creates a child datum which is linked through the results container to this parent.
1212
*/
13-
public GraphqlExecutionNodeDatum createAndPutChildDatum(String fieldName, Object value) {
13+
public GraphqlExecutionNodeDatum22 createAndPutChildDatum(String fieldName, Object value) {
1414
Map<String,Object> map = new HashMap<>();
1515
putResult(fieldName, map);
16-
return new GraphqlExecutionNodeDatum(map, value);
16+
return new GraphqlExecutionNodeDatum22(map, value);
1717
}
1818

19-
public GraphqlExecutionResultList createAndPutEmptyChildList(String fieldName) {
19+
public GraphqlExecutionResultList2 createAndPutEmptyChildList(String fieldName) {
2020
List<Object> resultList = new ArrayList<>();
2121
putResult(fieldName, resultList);
22-
return new GraphqlExecutionResultList(resultList);
22+
return new GraphqlExecutionResultList2(resultList);
2323
}
2424

2525
/**

src/main/java/graphql/execution/batched/GraphqlExecutionResultList.java renamed to src/main/java/graphql/execution/batched/GraphqlExecutionResultList2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import java.util.List;
44

5-
public class GraphqlExecutionResultList extends GraphqlExecutionResultContainer {
5+
public class GraphqlExecutionResultList2 extends GraphqlExecutionResultContainer2 {
66

77
private final List<Object> results;
88

9-
public GraphqlExecutionResultList(List<Object> results) {
9+
public GraphqlExecutionResultList2(List<Object> results) {
1010
this.results = results;
1111
}
1212

0 commit comments

Comments
 (0)