4
4
import com .fasterxml .jackson .databind .ObjectMapper ;
5
5
import com .fasterxml .jackson .databind .node .ArrayNode ;
6
6
import com .fasterxml .jackson .databind .node .ObjectNode ;
7
- import graphql .language .*;
7
+ import graphql .language .Argument ;
8
+ import graphql .language .BooleanValue ;
9
+ import graphql .language .Field ;
10
+ import graphql .language .IntValue ;
11
+ import graphql .language .Node ;
12
+ import graphql .language .Selection ;
13
+ import graphql .language .SelectionSet ;
14
+ import graphql .language .StringValue ;
15
+ import graphql .language .Value ;
8
16
import org .apache .jena .rdf .model .Model ;
9
17
import org .apache .log4j .Logger ;
10
18
import org .hypergraphql .config .schema .FieldOfTypeConfig ;
11
- import org .hypergraphql .datamodel .HGQLSchema ;
12
19
import org .hypergraphql .config .schema .HGQLVocabulary ;
13
20
import org .hypergraphql .datafetching .services .Service ;
14
-
15
- import java .util .*;
21
+ import org .hypergraphql .datamodel .HGQLSchema ;
22
+ import org .hypergraphql .exception .HGQLConfigurationException ;
23
+
24
+ import java .util .Collection ;
25
+ import java .util .HashMap ;
26
+ import java .util .HashSet ;
27
+ import java .util .List ;
28
+ import java .util .Map ;
29
+ import java .util .Set ;
30
+ import java .util .UUID ;
16
31
import java .util .concurrent .ExecutionException ;
17
32
import java .util .concurrent .ExecutorService ;
18
33
import java .util .concurrent .Executors ;
@@ -58,7 +73,6 @@ public String getExecutionId() {
58
73
return executionId ;
59
74
}
60
75
61
-
62
76
public Map <String , String > getFullLdContext () {
63
77
64
78
Map <String , String > result = new HashMap <>(ldContext );
@@ -77,7 +91,11 @@ public Map<String, String> getFullLdContext() {
77
91
78
92
public ExecutionTreeNode (Field field , String nodeId , HGQLSchema schema ) {
79
93
80
- this .service = schema .getQueryFields ().get (field .getName ()).service ();
94
+ if (schema .getQueryFields ().containsKey (field .getName ())) {
95
+ this .service = schema .getQueryFields ().get (field .getName ()).service ();
96
+ } else {
97
+ throw new HGQLConfigurationException ("Field '" + field .getName () + "' not found in schema" );
98
+ }
81
99
this .executionId = createId ();
82
100
this .childrenNodes = new HashMap <>();
83
101
this .ldContext = new HashMap <>();
@@ -113,14 +131,14 @@ public String toString(int i) {
113
131
.append (space ).append ("Query: " ).append (this .query .toString ()).append ("\n " )
114
132
.append (space ).append ("Root type: " ).append (this .rootType ).append ("\n " )
115
133
.append (space ).append ("LD context: " ).append (this .ldContext .toString ()).append ("\n " );
116
- Set <String > children = this .childrenNodes .keySet ();
134
+ Set <Map . Entry < String , ExecutionForest >> children = this .childrenNodes .entrySet ();
117
135
if (!children .isEmpty ()) {
118
136
result .append (space ).append ("Children nodes: \n " );
119
- for (String child : children ) {
137
+ for (Map . Entry < String , ExecutionForest > child : children ) {
120
138
result .append (space ).append ("\t Parent marker: " )
121
- .append (child ).append ("\n " )
139
+ .append (child . getKey () ).append ("\n " )
122
140
.append (space ).append ("\t Children execution nodes: \n " )
123
- .append (this . childrenNodes . get ( child ).toString (i +1 )).append ("\n " );
141
+ .append (child . getValue ( ).toString (i +1 )).append ("\n " );
124
142
}
125
143
}
126
144
@@ -189,7 +207,7 @@ private String getContextLdValue(String contextLdKey) {
189
207
private JsonNode traverse (Field field , String parentId , String parentType ) {
190
208
191
209
SelectionSet subFields = field .getSelectionSet ();
192
- if (subFields != null ) {
210
+ if (subFields != null ) {
193
211
194
212
FieldOfTypeConfig fieldConfig = hgqlSchema .getTypes ().get (parentType ).getField (field .getName ());
195
213
String targetName = fieldConfig .getTargetName ();
@@ -198,10 +216,15 @@ private JsonNode traverse(Field field, String parentId, String parentType) {
198
216
199
217
Set <Service > serviceCalls = splitFields .keySet ();
200
218
201
-
202
- for (Service serviceCall : serviceCalls ) {
203
- if (serviceCall != this .service ) {
204
- ExecutionTreeNode childNode = new ExecutionTreeNode (serviceCall , splitFields .get (serviceCall ), parentId , targetName , hgqlSchema );
219
+ for (Map .Entry <Service , Set <Field >> entry : splitFields .entrySet ()) {
220
+ if (!entry .getKey ().equals (this .service )) {
221
+ ExecutionTreeNode childNode = new ExecutionTreeNode (
222
+ entry .getKey (),
223
+ entry .getValue (),
224
+ parentId ,
225
+ targetName ,
226
+ hgqlSchema
227
+ );
205
228
206
229
if (this .childrenNodes .containsKey (parentId )) {
207
230
try {
@@ -291,8 +314,17 @@ private Map<Service, Set<Field>> getPartitionedFields(String parentType, Selecti
291
314
292
315
Service serviceConfig ;
293
316
294
- serviceConfig = hgqlSchema .getTypes ().get (parentType ). getFields (). get ( field . getName ()). getService ();
317
+ if ( hgqlSchema .getTypes ().containsKey (parentType )) {
295
318
319
+ if (hgqlSchema .getTypes ().get (parentType ).getFields ().containsKey (field .getName ())) {
320
+ serviceConfig = hgqlSchema .getTypes ().get (parentType ).getFields ().get (field .getName ()).getService ();
321
+ } else {
322
+ throw new HGQLConfigurationException ("Schema is missing field '"
323
+ + parentType + "::" + field .getName () + "'" );
324
+ }
325
+ } else {
326
+ throw new HGQLConfigurationException ("Schema is missing type '" + parentType + "'" );
327
+ }
296
328
297
329
if (result .containsKey (serviceConfig )) {
298
330
0 commit comments