11package graphql ;
22
33import graphql .cachecontrol .CacheControl ;
4+ import graphql .execution .ExecutionId ;
45import org .dataloader .DataLoaderRegistry ;
56
67import java .util .Collections ;
@@ -22,21 +23,23 @@ public class ExecutionInput {
2223 private final Map <String , Object > variables ;
2324 private final DataLoaderRegistry dataLoaderRegistry ;
2425 private final CacheControl cacheControl ;
26+ private final ExecutionId executionId ;
2527
2628
2729 public ExecutionInput (String query , String operationName , Object context , Object root , Map <String , Object > variables ) {
28- this (query , operationName , context , root , variables , new DataLoaderRegistry (), null );
30+ this (query , operationName , context , root , variables , new DataLoaderRegistry (), null , null );
2931 }
3032
3133 @ Internal
32- private ExecutionInput (String query , String operationName , Object context , Object root , Map <String , Object > variables , DataLoaderRegistry dataLoaderRegistry , CacheControl cacheControl ) {
34+ private ExecutionInput (String query , String operationName , Object context , Object root , Map <String , Object > variables , DataLoaderRegistry dataLoaderRegistry , CacheControl cacheControl , ExecutionId executionId ) {
3335 this .query = query ;
3436 this .operationName = operationName ;
3537 this .context = context ;
3638 this .root = root ;
3739 this .variables = variables ;
3840 this .dataLoaderRegistry = dataLoaderRegistry ;
3941 this .cacheControl = cacheControl ;
42+ this .executionId = executionId ;
4043 }
4144
4245 /**
@@ -88,23 +91,30 @@ public CacheControl getCacheControl() {
8891 return cacheControl ;
8992 }
9093
94+ /**
95+ * @return Id that will be/was used to execute this operation.
96+ */
97+ public ExecutionId getExecutionId () {
98+ return executionId ;
99+ }
100+
91101 /**
92102 * This helps you transform the current ExecutionInput object into another one by starting a builder with all
93103 * the current values and allows you to transform it how you want.
94104 *
95105 * @param builderConsumer the consumer code that will be given a builder to transform
96- *
97106 * @return a new ExecutionInput object based on calling build on that builder
98107 */
99108 public ExecutionInput transform (Consumer <Builder > builderConsumer ) {
100109 Builder builder = new Builder ()
101- .query (this .query )
102- .operationName (this .operationName )
103- .context (this .context )
104- .root (this .root )
105- .dataLoaderRegistry (this .dataLoaderRegistry )
106- .cacheControl (this .cacheControl )
107- .variables (this .variables );
110+ .query (this .query )
111+ .operationName (this .operationName )
112+ .context (this .context )
113+ .root (this .root )
114+ .dataLoaderRegistry (this .dataLoaderRegistry )
115+ .cacheControl (this .cacheControl )
116+ .variables (this .variables )
117+ .executionId (executionId );
108118
109119 builderConsumer .accept (builder );
110120
@@ -115,13 +125,14 @@ public ExecutionInput transform(Consumer<Builder> builderConsumer) {
115125 @ Override
116126 public String toString () {
117127 return "ExecutionInput{" +
118- "query='" + query + '\'' +
119- ", operationName='" + operationName + '\'' +
120- ", context=" + context +
121- ", root=" + root +
122- ", variables=" + variables +
123- ", dataLoaderRegistry=" + dataLoaderRegistry +
124- '}' ;
128+ "query='" + query + '\'' +
129+ ", operationName='" + operationName + '\'' +
130+ ", context=" + context +
131+ ", root=" + root +
132+ ", variables=" + variables +
133+ ", dataLoaderRegistry=" + dataLoaderRegistry +
134+ ", executionId= " + executionId +
135+ '}' ;
125136 }
126137
127138 /**
@@ -135,7 +146,6 @@ public static Builder newExecutionInput() {
135146 * Creates a new builder of ExecutionInput objects with the given query
136147 *
137148 * @param query the query to execute
138- *
139149 * @return a new builder of ExecutionInput objects
140150 */
141151 public static Builder newExecutionInput (String query ) {
@@ -151,6 +161,7 @@ public static class Builder {
151161 private Map <String , Object > variables = Collections .emptyMap ();
152162 private DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry ();
153163 private CacheControl cacheControl = CacheControl .newCacheControl ();
164+ private ExecutionId executionId = null ;
154165
155166 public Builder query (String query ) {
156167 this .query = query ;
@@ -162,11 +173,20 @@ public Builder operationName(String operationName) {
162173 return this ;
163174 }
164175
176+ /**
177+ * A default one will be assigned, but you can set your own.
178+ * @param executionId an execution id object
179+ * @return this builder
180+ */
181+ public Builder executionId (ExecutionId executionId ) {
182+ this .executionId = executionId ;
183+ return this ;
184+ }
185+
165186 /**
166187 * By default you will get a {@link GraphQLContext} object but you can set your own.
167188 *
168189 * @param context the context object to use
169- *
170190 * @return this builder
171191 */
172192 public Builder context (Object context ) {
@@ -196,11 +216,11 @@ public Builder variables(Map<String, Object> variables) {
196216 }
197217
198218 /**
199- * You should create new {@link org.dataloader.DataLoaderRegistry}s and new {@link org.dataloader.DataLoader}s for each execution. Do not re-use
219+ * You should create new {@link org.dataloader.DataLoaderRegistry}s and new {@link org.dataloader.DataLoader}s for each execution. Do not
220+ * re-use
200221 * instances as this will create unexpected results.
201222 *
202223 * @param dataLoaderRegistry a registry of {@link org.dataloader.DataLoader}s
203- *
204224 * @return this builder
205225 */
206226 public Builder dataLoaderRegistry (DataLoaderRegistry dataLoaderRegistry ) {
@@ -214,7 +234,7 @@ public Builder cacheControl(CacheControl cacheControl) {
214234 }
215235
216236 public ExecutionInput build () {
217- return new ExecutionInput (query , operationName , context , root , variables , dataLoaderRegistry , cacheControl );
237+ return new ExecutionInput (query , operationName , context , root , variables , dataLoaderRegistry , cacheControl , executionId );
218238 }
219239 }
220- }
240+ }
0 commit comments