22
33
44import graphql .execution .Execution ;
5+ import graphql .execution .ExecutionId ;
6+ import graphql .execution .ExecutionIdProvider ;
57import graphql .execution .ExecutionStrategy ;
68import graphql .language .Document ;
79import graphql .language .SourceLocation ;
@@ -26,6 +28,18 @@ public class GraphQL {
2628
2729 private final GraphQLSchema graphQLSchema ;
2830 private final ExecutionStrategy executionStrategy ;
31+ //
32+ // later PR changes will allow api consumers to provide their own id provider
33+ //
34+ // see https://github.com/graphql-java/graphql-java/pull/276 for the builder pattern
35+ // needed to make this sustainable. But for now we will use hard coded approach.
36+ //
37+ private final ExecutionIdProvider idProvider = new ExecutionIdProvider () {
38+ @ Override
39+ public ExecutionId generate (String query , String operationName , Object context ) {
40+ return ExecutionId .generate ();
41+ }
42+ };
2943
3044 private static final Logger log = LoggerFactory .getLogger (GraphQL .class );
3145
@@ -66,16 +80,19 @@ public ExecutionResult execute(String requestString, String operationName, Objec
6680 RecognitionException recognitionException = (RecognitionException ) e .getCause ();
6781 SourceLocation sourceLocation = new SourceLocation (recognitionException .getOffendingToken ().getLine (), recognitionException .getOffendingToken ().getCharPositionInLine ());
6882 InvalidSyntaxError invalidSyntaxError = new InvalidSyntaxError (sourceLocation );
69- return new ExecutionResultImpl (Arrays . asList (invalidSyntaxError ));
83+ return new ExecutionResultImpl (Collections . singletonList (invalidSyntaxError ));
7084 }
7185
7286 Validator validator = new Validator ();
7387 List <ValidationError > validationErrors = validator .validateDocument (graphQLSchema , document );
7488 if (validationErrors .size () > 0 ) {
7589 return new ExecutionResultImpl (validationErrors );
7690 }
91+
92+ ExecutionId executionId = idProvider .generate (requestString , operationName , context );
93+
7794 Execution execution = new Execution (executionStrategy );
78- return execution .execute (graphQLSchema , context , document , operationName , arguments );
95+ return execution .execute (executionId , graphQLSchema , context , document , operationName , arguments );
7996 }
8097
8198
0 commit comments