1111
1212import java .util .Map ;
1313import java .util .function .Consumer ;
14+ import java .util .function .Supplier ;
1415
1516import static graphql .Assert .assertNotNull ;
1617import static graphql .Assert .assertTrue ;
@@ -64,28 +65,23 @@ public class ExecutionStepInfo {
6465 private final MergedField field ;
6566 private final GraphQLFieldDefinition fieldDefinition ;
6667 private final GraphQLObjectType fieldContainer ;
67- private final ImmutableMapWithNullValues <String , Object > arguments ;
68-
69- private ExecutionStepInfo (GraphQLOutputType type ,
70- GraphQLFieldDefinition fieldDefinition ,
71- MergedField field ,
72- ResultPath path ,
73- ExecutionStepInfo parent ,
74- ImmutableMapWithNullValues <String , Object > arguments ,
75- GraphQLObjectType fieldsContainer ) {
76- this .fieldDefinition = fieldDefinition ;
77- this .field = field ;
78- this .path = path ;
79- this .parent = parent ;
80- this .type = assertNotNull (type , () -> "you must provide a graphql type" );
81- this .arguments = arguments ;
82- this .fieldContainer = fieldsContainer ;
68+ private final Supplier <ImmutableMapWithNullValues <String , Object >> arguments ;
69+
70+ private ExecutionStepInfo (Builder builder ) {
71+ this .fieldDefinition = builder .fieldDefinition ;
72+ this .field = builder .field ;
73+ this .path = builder .path ;
74+ this .parent = builder .parentInfo ;
75+ this .type = assertNotNull (builder .type , () -> "you must provide a graphql type" );
76+ this .arguments = builder .arguments ;
77+ this .fieldContainer = builder .fieldContainer ;
8378 }
8479
8580 /**
8681 * @return the GraphQLObjectType defining the {@link #getFieldDefinition()}
87- * @deprecated use {@link #getObjectType()} instead as it is named better
82+ *
8883 * @see ExecutionStepInfo#getObjectType()
84+ * @deprecated use {@link #getObjectType()} instead as it is named better
8985 */
9086 @ Deprecated
9187 public GraphQLObjectType getFieldContainer () {
@@ -165,19 +161,20 @@ public boolean isListType() {
165161 * @return the resolved arguments that have been passed to this field
166162 */
167163 public Map <String , Object > getArguments () {
168- return arguments ;
164+ return arguments . get () ;
169165 }
170166
171167 /**
172168 * Returns the named argument
173169 *
174170 * @param name the name of the argument
175171 * @param <T> you decide what type it is
172+ *
176173 * @return the named argument or null if its not present
177174 */
178175 @ SuppressWarnings ("unchecked" )
179176 public <T > T getArgument (String name ) {
180- return (T ) arguments .get (name );
177+ return (T ) getArguments () .get (name );
181178 }
182179
183180 /**
@@ -201,14 +198,15 @@ public boolean hasParent() {
201198 * after type resolution has occurred
202199 *
203200 * @param newType the new type to be
201+ *
204202 * @return a new type info with the same
205203 */
206204 public ExecutionStepInfo changeTypeWithPreservedNonNull (GraphQLOutputType newType ) {
207205 assertTrue (!GraphQLTypeUtil .isNonNull (newType ), () -> "newType can't be non null" );
208206 if (isNonNullType ()) {
209- return new ExecutionStepInfo ( GraphQLNonNull .nonNull (newType ), fieldDefinition , field , path , this . parent , arguments , this . fieldContainer );
207+ return newExecutionStepInfo ( this ). type ( GraphQLNonNull .nonNull (newType )). build ( );
210208 } else {
211- return new ExecutionStepInfo ( newType , fieldDefinition , field , path , this . parent , arguments , this . fieldContainer );
209+ return newExecutionStepInfo ( this ). type ( newType ). build ( );
212210 }
213211 }
214212
@@ -257,13 +255,13 @@ public static class Builder {
257255 GraphQLObjectType fieldContainer ;
258256 MergedField field ;
259257 ResultPath path ;
260- ImmutableMapWithNullValues <String , Object > arguments ;
258+ Supplier < ImmutableMapWithNullValues <String , Object > > arguments ;
261259
262260 /**
263261 * @see ExecutionStepInfo#newExecutionStepInfo()
264262 */
265263 private Builder () {
266- arguments = ImmutableMapWithNullValues . emptyMap () ;
264+ arguments = ImmutableMapWithNullValues :: emptyMap ;
267265 }
268266
269267 private Builder (ExecutionStepInfo existing ) {
@@ -273,7 +271,7 @@ private Builder(ExecutionStepInfo existing) {
273271 this .fieldContainer = existing .fieldContainer ;
274272 this .field = existing .field ;
275273 this .path = existing .path ;
276- this .arguments = ImmutableMapWithNullValues . copyOf ( existing .getArguments ()) ;
274+ this .arguments = existing .arguments ;
277275 }
278276
279277 public Builder type (GraphQLOutputType type ) {
@@ -301,8 +299,11 @@ public Builder path(ResultPath resultPath) {
301299 return this ;
302300 }
303301
304- public Builder arguments (Map <String , Object > arguments ) {
305- this .arguments = arguments == null ? ImmutableMapWithNullValues .emptyMap () : ImmutableMapWithNullValues .copyOf (arguments );
302+ public Builder arguments (Supplier <Map <String , Object >> arguments ) {
303+ this .arguments = () -> {
304+ Map <String , Object > map = arguments .get ();
305+ return map == null ? ImmutableMapWithNullValues .emptyMap () : ImmutableMapWithNullValues .copyOf (map );
306+ };
306307 return this ;
307308 }
308309
@@ -312,7 +313,7 @@ public Builder fieldContainer(GraphQLObjectType fieldContainer) {
312313 }
313314
314315 public ExecutionStepInfo build () {
315- return new ExecutionStepInfo (type , fieldDefinition , field , path , parentInfo , arguments , fieldContainer );
316+ return new ExecutionStepInfo (this );
316317 }
317318 }
318319}
0 commit comments