-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Replace ExecuteSelectionSet
with ExecuteCollectedFields
#1039
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
4d62b8b
to
b342b58
Compare
(Rebased on |
b342b58
to
a52310e
Compare
(Rebased on |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@benjie we need to formally define "grouped field set" in Section 2 "Language". You might have done so in a prior PR that I missed. Here is the link to us defining "section sets" in section 2 https://spec.graphql.org/draft/#sec-Selection-Sets |
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.
Nits because we agreed to name things responseName
instead of responseKey
* Consistently use 'response key' not 'response name' * Extract definition of response key from #1039 * Utilise definition * response key -> response name * Fix names in algorithms * latest changes --------- Co-authored-by: Lee Byron <lee@leebyron.com>
@benjie this change looks good but has some conflicts with the other changes pulled out and recently merged. Want to rebase and fix? Then I'll get this one merged |
spec/Section 6 -- Execution.md
Outdated
:: A _grouped field set_ is a map where each entry is a list of field selections | ||
that share a _response name_ (the alias if defined, otherwise the field name). | ||
|
||
Before execution, the _selection set_ is converted to a _grouped field set_ by | ||
calling {CollectFields()}. This ensures all fields with the same response name | ||
(including those in referenced fragments) are executed at the same time. |
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.
These are the only lines that have actually been changed in Field Collection, everything else was just moved.
(To prove this, take the current Field Collection
text and paste it over this PR, the diff should render as:
diff --git i/spec/Section 6 -- Execution.md w/spec/Section 6 -- Execution.md
index f81e38d..549930f 100644
--- i/spec/Section 6 -- Execution.md
+++ w/spec/Section 6 -- Execution.md
@@ -374,12 +374,11 @@ serial):
### Field Collection
-:: A _grouped field set_ is a map where each entry is a list of field selections
-that share a _response name_ (the alias if defined, otherwise the field name).
-
-Before execution, the _selection set_ is converted to a _grouped field set_ by
-calling {CollectFields()}. This ensures all fields with the same response name
-(including those in referenced fragments) are executed at the same time.
+Before execution, the _selection set_ is converted to a grouped field set by
+calling {CollectFields()}. Each entry in the grouped field set is a list of
+fields that share a _response name_ (the alias if defined, otherwise the field
+name). This ensures all fields with the same response name (including those in
+referenced fragments) are executed at the same time.
As an example, collecting the fields of this selection set would collect two
instances of the field `a` and one of field `b`:
)
@leebyron I opted for a merge instead as it was less work, this is now good to review again. (I diffed the diffs and only the expected changes have come through, I also searched for "response key" and |
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.
Really love this cleanup, much closer to GraphQL.js
@benjie I took a pass at some re-ordering of the content here, I'd be curious for your feedback. Also, I think "Grouped Field Set" has become a confusing name. Ideally this term "Collect" is what we use for this concept (instead of "group") and it's a bit weird this is called a "Set" when in fact its type is "Collected Field Map"? |
553dc1a
to
d68df95
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Scratch that. I'd be happy with "Collected Fields Map", but I think it's important "field" is plural, either via
|
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.
Thanks for the edits @leebyron! I'm generally in favour, but have a few suggestions.
spec/Section 6 -- Execution.md
Outdated
:: A _grouped field set_ is a map where each entry is a _response name_ and a | ||
list of selected fields that share that _response name_ (the field alias if | ||
defined, otherwise the field's name). |
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.
If we choose not to rename "grouped field set", we should at least define it in terms of a set:
:: A _grouped field set_ is a map where each entry is a _response name_ and a | |
list of selected fields that share that _response name_ (the field alias if | |
defined, otherwise the field's name). | |
:: A _grouped field set_ is a map where each entry is a _response name_ and an | |
ordered set of selected fields that share that _response name_ (the field alias | |
if defined, otherwise the field's name). |
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.
If we accept this, we should also make a few other changes such as:
-Initialize groupedFields to an empty ordered map of lists.
+Initialize groupedFields to an empty ordered map of ordered sets.
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.
There's no functional change between a list or a set in this case since the algorithm never attempts to add the same item to the set/list?
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.
Yes indeed, list or ordered set is equivalent here since it will never include duplicates. The main reason to change it to set is because we call it a "grouped field set"; a "field set" being OrderedSet<Field>
, and grouped being a map grouped by response key: Map<string, OrderedSet<Field>>
. Technically we have Map<string, Field[]>
currently, and calling that a "grouped field set" causes the confusion because no "set" is involved.
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 might be a simpler solve actually:
:: A _grouped field set_ is a map where each entry is a _response name_ and a | |
list of selected fields that share that _response name_ (the field alias if | |
defined, otherwise the field's name). | |
:: A _grouped field set_ is a map where each entry is a _response name_ and a | |
list of selected fields that share that _response name_ (the field alias if | |
defined, otherwise the field's name). | |
Note: No entry in the list of selected fields will be duplicated, hence we call | |
it a "field set" even though in the algorithms we use a list structure for it. |
Worth mentioning here that the data structure returned by CollectFields will have to change to support type FieldDetails = { field: Field, deferUsage: DeferUsage }
type GroupedFieldSet = Map<string, List<FieldDetails>> |
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.
LGTM 👍
Having thought about it more, I'm in favour of keeping "grouped field set" - I think it's descriptive of a field set that has been grouped by response key, I think the only issue really is that we use a list instead of a set in the algorithms. Moreover, I think that an individual "field set" is in itself useful - we call it "fields" rather than "field set" in CompleteValue() but it's the same thing.
71c82b1
to
c7532d1
Compare
ExecuteSelectionSet
with ExecuteGroupedFieldSet
ExecuteSelectionSet
with ExecuteCollectedFields
@leebyron To reflect your discussion above, I've renamed "ExecuteGroupedFieldSet" to "ExecuteCollectedFields" and that definitely flows better. However, I think that "grouped field set" is still the right term to refer to the structure and actually defining a "field set" in general adds a lot of clarity to a number of algorithms (e.g. This makes the algorithms a lot clearer to me: -CollectSubfields(objectType, fields, variableValues):
+CollectSubfields(objectType, fieldSet, variableValues): ^ Knowing that a "field set" is a set of field selections that share the same response key makes this algorithms purpose a lot clearer -ExecuteField(objectType, objectValue, fieldType, fields, variableValues):
+ExecuteField(objectType, objectValue, fieldType, fieldSet, variableValues): ^ A lot more intuitive what -CompleteValue(fieldType, fields, result, variableValues):
+CompleteValue(fieldType, fieldSet, result, variableValues): ^ Same |
c7532d1
to
6e76340
Compare
6e76340
to
3c6dfb3
Compare
:: A _field set_ is a list of selected fields that share the same _response | ||
name_ (the field alias if defined, otherwise the field's name). | ||
|
||
Note: The order of field selections in a _field set_ is significant, hence the | ||
algorithms in this specification model it as a list. Any later duplicated field | ||
selections in a field set will not impact its interpretation, so using an | ||
ordered set would yield equivalent results. |
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.
@@ -757,7 +757,7 @@ type Person { | |||
} | |||
``` | |||
|
|||
Valid operations must supply a nested field set for any field that returns an | |||
Valid operations must supply a selection of fields for any field that returns an |
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.
Not directly related to this PR but a more precise wording would be to use selectionSet
here as fragments are also valid, not only fields.
Valid operations must supply a selection of fields for any field that returns an | |
Valid operations must supply a valid sub _selection set_ for any field that returns an |
Essentially this PR replaces the
ExecuteSelectionSet
method withExecuteCollectedFields
(which essentially just drops the first line ofExecuteSelectionSet
, which was responsible for collecting fields to be executed). It then refactors the rest of the spec to accommodate this change, reducing the repetition inExecuteQuery
,ExecuteMutation
andExecuteSubscriptionEvent
; and removingMergeSelectionSets
(which generated a "virtual" selection set to accomodate theExecuteSelectionSet
method), instead adding aCollectSubfields
algorithm which produces a grouped field set directly, ready for execution.I extracted this common refactoring from a number of my attempts to write spec changes for the
@defer
and@stream
directives - it turns out that this refactoring of the spec was always needed as a base for my changes. Similarly, @yaacovCR found similar in his attempts to address this same problem, and raised #999 extracted from his solution. This PR was introduced independently of #999 (other than using theCollectSubfields
algorithm name) however there is significant alignment, so @yaacovCR suggested that I raise it as an alternative PR.It may be easier to review this PR in "split" view rather than "unified" view.