-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make ExecutionStepInfo values be lazy #2749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
|
|
||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Supplier; | ||
|
|
||
| import static graphql.Assert.assertNotNull; | ||
| import static graphql.Assert.assertTrue; | ||
|
|
@@ -64,28 +65,23 @@ public class ExecutionStepInfo { | |
| private final MergedField field; | ||
| private final GraphQLFieldDefinition fieldDefinition; | ||
| private final GraphQLObjectType fieldContainer; | ||
| private final ImmutableMapWithNullValues<String, Object> arguments; | ||
|
|
||
| private ExecutionStepInfo(GraphQLOutputType type, | ||
| GraphQLFieldDefinition fieldDefinition, | ||
| MergedField field, | ||
| ResultPath path, | ||
| ExecutionStepInfo parent, | ||
| ImmutableMapWithNullValues<String, Object> arguments, | ||
| GraphQLObjectType fieldsContainer) { | ||
| this.fieldDefinition = fieldDefinition; | ||
| this.field = field; | ||
| this.path = path; | ||
| this.parent = parent; | ||
| this.type = assertNotNull(type, () -> "you must provide a graphql type"); | ||
| this.arguments = arguments; | ||
| this.fieldContainer = fieldsContainer; | ||
| private final Supplier<ImmutableMapWithNullValues<String, Object>> arguments; | ||
|
|
||
| private ExecutionStepInfo(Builder builder) { | ||
| this.fieldDefinition = builder.fieldDefinition; | ||
| this.field = builder.field; | ||
| this.path = builder.path; | ||
| this.parent = builder.parentInfo; | ||
| this.type = assertNotNull(builder.type, () -> "you must provide a graphql type"); | ||
| this.arguments = builder.arguments; | ||
| this.fieldContainer = builder.fieldContainer; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to builder as arg - modernisation |
||
| } | ||
|
|
||
| /** | ||
| * @return the GraphQLObjectType defining the {@link #getFieldDefinition()} | ||
| * @deprecated use {@link #getObjectType()} instead as it is named better | ||
| * | ||
| * @see ExecutionStepInfo#getObjectType() | ||
| * @deprecated use {@link #getObjectType()} instead as it is named better | ||
| */ | ||
| @Deprecated | ||
| public GraphQLObjectType getFieldContainer() { | ||
|
|
@@ -165,19 +161,20 @@ public boolean isListType() { | |
| * @return the resolved arguments that have been passed to this field | ||
| */ | ||
| public Map<String, Object> getArguments() { | ||
| return arguments; | ||
| return arguments.get(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the named argument | ||
| * | ||
| * @param name the name of the argument | ||
| * @param <T> you decide what type it is | ||
| * | ||
| * @return the named argument or null if its not present | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| public <T> T getArgument(String name) { | ||
| return (T) arguments.get(name); | ||
| return (T) getArguments().get(name); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -201,14 +198,15 @@ public boolean hasParent() { | |
| * after type resolution has occurred | ||
| * | ||
| * @param newType the new type to be | ||
| * | ||
| * @return a new type info with the same | ||
| */ | ||
| public ExecutionStepInfo changeTypeWithPreservedNonNull(GraphQLOutputType newType) { | ||
| assertTrue(!GraphQLTypeUtil.isNonNull(newType), () -> "newType can't be non null"); | ||
| if (isNonNullType()) { | ||
| return new ExecutionStepInfo(GraphQLNonNull.nonNull(newType), fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); | ||
| return newExecutionStepInfo(this).type(GraphQLNonNull.nonNull(newType)).build(); | ||
| } else { | ||
| return new ExecutionStepInfo(newType, fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); | ||
| return newExecutionStepInfo(this).type(newType).build(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -257,13 +255,13 @@ public static class Builder { | |
| GraphQLObjectType fieldContainer; | ||
| MergedField field; | ||
| ResultPath path; | ||
| ImmutableMapWithNullValues<String, Object> arguments; | ||
| Supplier<ImmutableMapWithNullValues<String, Object>> arguments; | ||
|
|
||
| /** | ||
| * @see ExecutionStepInfo#newExecutionStepInfo() | ||
| */ | ||
| private Builder() { | ||
| arguments = ImmutableMapWithNullValues.emptyMap(); | ||
| arguments = ImmutableMapWithNullValues::emptyMap; | ||
| } | ||
|
|
||
| private Builder(ExecutionStepInfo existing) { | ||
|
|
@@ -273,7 +271,7 @@ private Builder(ExecutionStepInfo existing) { | |
| this.fieldContainer = existing.fieldContainer; | ||
| this.field = existing.field; | ||
| this.path = existing.path; | ||
| this.arguments = ImmutableMapWithNullValues.copyOf(existing.getArguments()); | ||
| this.arguments = existing.arguments; | ||
| } | ||
|
|
||
| public Builder type(GraphQLOutputType type) { | ||
|
|
@@ -301,8 +299,11 @@ public Builder path(ResultPath resultPath) { | |
| return this; | ||
| } | ||
|
|
||
| public Builder arguments(Map<String, Object> arguments) { | ||
| this.arguments = arguments == null ? ImmutableMapWithNullValues.emptyMap() : ImmutableMapWithNullValues.copyOf(arguments); | ||
| public Builder arguments(Supplier<Map<String, Object>> arguments) { | ||
| this.arguments = () -> { | ||
| Map<String, Object> map = arguments.get(); | ||
| return map == null ? ImmutableMapWithNullValues.emptyMap() : ImmutableMapWithNullValues.copyOf(map); | ||
| }; | ||
| return this; | ||
| } | ||
|
|
||
|
|
@@ -312,7 +313,7 @@ public Builder fieldContainer(GraphQLObjectType fieldContainer) { | |
| } | ||
|
|
||
| public ExecutionStepInfo build() { | ||
| return new ExecutionStepInfo(type, fieldDefinition, field, path, parentInfo, arguments, fieldContainer); | ||
| return new ExecutionStepInfo(this); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a viral change - type resolving wont materialise the ESI arguments unless it has to