@@ -21,6 +21,7 @@ public class ExecutionInput {
2121 private final String query ;
2222 private final String operationName ;
2323 private final Object context ;
24+ private final Object localContext ;
2425 private final Object root ;
2526 private final Map <String , Object > variables ;
2627 private final DataLoaderRegistry dataLoaderRegistry ;
@@ -30,8 +31,8 @@ public class ExecutionInput {
3031
3132
3233 @ Internal
33- private ExecutionInput (String query , String operationName , Object context , Object root , Map <String , Object > variables , DataLoaderRegistry dataLoaderRegistry , CacheControl cacheControl , ExecutionId executionId , Locale locale ) {
34- this .query = assertNotNull (query , "query can't be null" );
34+ private ExecutionInput (String query , String operationName , Object context , Object root , Map <String , Object > variables , DataLoaderRegistry dataLoaderRegistry , CacheControl cacheControl , ExecutionId executionId , Locale locale , Object localContext ) {
35+ this .query = assertNotNull (query , () -> "query can't be null" );
3536 this .operationName = operationName ;
3637 this .context = context ;
3738 this .root = root ;
@@ -40,6 +41,7 @@ private ExecutionInput(String query, String operationName, Object context, Objec
4041 this .cacheControl = cacheControl ;
4142 this .executionId = executionId ;
4243 this .locale = locale ;
44+ this .localContext = localContext ;
4345 }
4446
4547 /**
@@ -62,6 +64,12 @@ public String getOperationName() {
6264 public Object getContext () {
6365 return context ;
6466 }
67+ /**
68+ * @return the local context object to pass to all top level (i.e. query, mutation, subscription) data fetchers
69+ */
70+ public Object getLocalContext () {
71+ return localContext ;
72+ }
6573
6674 /**
6775 * @return the root object to start the query execution on
@@ -119,6 +127,7 @@ public ExecutionInput transform(Consumer<Builder> builderConsumer) {
119127 .query (this .query )
120128 .operationName (this .operationName )
121129 .context (this .context )
130+ .localContext (this .localContext )
122131 .root (this .root )
123132 .dataLoaderRegistry (this .dataLoaderRegistry )
124133 .cacheControl (this .cacheControl )
@@ -167,6 +176,7 @@ public static class Builder {
167176 private String query ;
168177 private String operationName ;
169178 private Object context = GraphQLContext .newContext ().build ();
179+ private Object localContext ;
170180 private Object root ;
171181 private Map <String , Object > variables = Collections .emptyMap ();
172182 //
@@ -179,7 +189,7 @@ public static class Builder {
179189 private ExecutionId executionId ;
180190
181191 public Builder query (String query ) {
182- this .query = assertNotNull (query , "query can't be null" );
192+ this .query = assertNotNull (query , () -> "query can't be null" );
183193 return this ;
184194 }
185195
@@ -212,6 +222,15 @@ public Builder locale(Locale locale) {
212222 return this ;
213223 }
214224
225+ /**
226+ * Sets initial localContext in root data fetchers
227+ * @return this builder
228+ */
229+ public Builder localContext (Object localContext ) {
230+ this .localContext = localContext ;
231+ return this ;
232+ }
233+
215234 /**
216235 * By default you will get a {@link GraphQLContext} object but you can set your own.
217236 *
@@ -240,7 +259,7 @@ public Builder root(Object root) {
240259 }
241260
242261 public Builder variables (Map <String , Object > variables ) {
243- this .variables = assertNotNull (variables , "variables map can't be null" );
262+ this .variables = assertNotNull (variables , () -> "variables map can't be null" );
244263 return this ;
245264 }
246265
@@ -263,7 +282,7 @@ public Builder cacheControl(CacheControl cacheControl) {
263282 }
264283
265284 public ExecutionInput build () {
266- return new ExecutionInput (query , operationName , context , root , variables , dataLoaderRegistry , cacheControl , executionId , locale );
285+ return new ExecutionInput (query , operationName , context , root , variables , dataLoaderRegistry , cacheControl , executionId , locale , localContext );
267286 }
268287 }
269288}
0 commit comments