@@ -348,21 +348,20 @@ Unsubscribe(responseStream):
348
348
349
349
## Executing Selection Sets
350
350
351
- The process of executing a GraphQL operation is to recursively execute every
352
- selected field in the operation. To do this, first all initially selected fields
353
- from the operation's top most _ root selection set_ are collected, then each
354
- executed. As each field completes, all its subfields are collected, then each
355
- executed. This process continues until there are no more subfields to collect
356
- and execute.
351
+ Executing a GraphQL operation recursively collects and executes every selected
352
+ field in the operation. First all initially selected fields from the operation's
353
+ top most _ root selection set_ are collected, then each executed. As each field
354
+ completes, all its subfields are collected, then each executed. This process
355
+ continues until there are no more subfields to collect and execute.
357
356
358
357
### Executing the Root Selection Set
359
358
360
359
:: A _ root selection set_ is the top level _ selection set_ provided by a GraphQL
361
360
operation. A root selection set always selects from a _ root operation type_ .
362
361
363
362
To execute the root selection set, the initial value being evaluated and the
364
- root type must be known, as well as whether it must be executed serially, or may
365
- be executed in parallel (see
363
+ root type must be known, as well as whether each field must be executed
364
+ serially, or normally by executing all fields in parallel (see
366
365
[ Normal and Serial Execution] ( #sec-Normal-and-Serial-Execution ) .
367
366
368
367
Executing the root selection set works similarly for queries (parallel),
@@ -386,22 +385,23 @@ executionMode):
386
385
387
386
### Field Collection
388
387
389
- Before execution, the _ root selection set_ is converted to a _ grouped field set_
390
- by calling {CollectFields()}. This ensures all fields with the same response
391
- name, including those in referenced fragments, are executed at the same time.
388
+ Before execution, each _ selection set_ is converted to a _ grouped field set_ by
389
+ calling {CollectFields()}. This ensures all fields with the same response name,
390
+ including those in referenced fragments, are executed at the same time.
392
391
393
392
:: A _ grouped field set_ is a map where each entry is a _ response name_ and its
394
393
associated _ field set_ . A _ grouped field set_ may be produced from a selection
395
394
set via {CollectFields()} or from the selection sets of a _ field set_ via
396
395
{CollectSubfields()}.
397
396
398
- :: A _ field set_ is a list of selected fields that share the same _ response
399
- name_ (the field alias if defined, otherwise the field's name).
397
+ :: A _ field set_ is an ordered set of selected fields that share the same
398
+ _ response name_ (the field alias if defined, otherwise the field's name).
399
+ Validation ensures each field in the set has the same name and arguments,
400
+ however each may have different subfields (see:
401
+ [ Field Selection Merging] ( #sec-Field-Selection-Merging ) ).
400
402
401
403
Note: The order of field selections in a _ field set_ is significant, hence the
402
- algorithms in this specification model it as a list. Any later duplicated field
403
- selections in a field set will not impact its interpretation, so using an
404
- ordered set would yield equivalent results.
404
+ algorithms in this specification model it as an ordered set.
405
405
406
406
As an example, collecting the fields of this query's selection set would result
407
407
in a grouped field set with two entries, ` "a" ` and ` "b" ` , with two instances of
@@ -430,7 +430,7 @@ response in a stable and predictable order.
430
430
CollectFields(objectType, selectionSet, variableValues, visitedFragments):
431
431
432
432
- If {visitedFragments} is not provided, initialize it to the empty set.
433
- - Initialize {groupedFields } to an empty ordered map of lists .
433
+ - Initialize {groupedFieldSet } to an empty ordered map of ordered sets .
434
434
- For each {selection} in {selectionSet}:
435
435
- If {selection} provides the directive ` @skip ` , let {skipDirective} be that
436
436
directive.
@@ -445,9 +445,9 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments):
445
445
- If {selection} is a {Field}:
446
446
- Let {responseName} be the _ response name_ of {selection} (the alias if
447
447
defined, otherwise the field name).
448
- - Let {groupForResponseName } be the list in {groupedFields } for
449
- {responseName}; if no such list exists, create it as an empty list .
450
- - Append {selection} to the {groupForResponseName }.
448
+ - Let {fieldsForResponseName } be the _ field set _ in {groupedFieldSet } for
449
+ {responseName}; if no such set exists, create it as an empty set .
450
+ - Append {selection} to the {fieldsForResponseName }.
451
451
- If {selection} is a {FragmentSpread}:
452
452
- Let {fragmentSpreadName} be the name of {selection}.
453
453
- If {fragmentSpreadName} is in {visitedFragments}, continue with the next
@@ -467,9 +467,9 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments):
467
467
- For each {fragmentGroup} in {fragmentGroupedFieldSet}:
468
468
- Let {responseName} be the response name shared by all fields in
469
469
{fragmentGroup}.
470
- - Let {groupForResponseName } be the list in {groupedFields } for
471
- {responseName}; if no such list exists, create it as an empty list .
472
- - Append all items in {fragmentGroup} to {groupForResponseName }.
470
+ - Let {fieldsForResponseName } be the _ field set _ in {groupedFieldSet } for
471
+ {responseName}; if no such set exists, create it as an empty set .
472
+ - Append all items in {fragmentGroup} to {fieldsForResponseName }.
473
473
- If {selection} is an {InlineFragment}:
474
474
- Let {fragmentType} be the type condition on {selection}.
475
475
- If {fragmentType} is not {null} and {DoesFragmentTypeApply(objectType,
@@ -482,32 +482,32 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments):
482
482
- For each {fragmentGroup} in {fragmentGroupedFieldSet}:
483
483
- Let {responseName} be the response name shared by all fields in
484
484
{fragmentGroup}.
485
- - Let {groupForResponseName } be the list in {groupedFields } for
486
- {responseName}; if no such list exists, create it as an empty list .
487
- - Append all items in {fragmentGroup} to {groupForResponseName }.
488
- - Return {groupedFields }.
485
+ - Let {fieldsForResponseName } be the _ field set _ in {groupedFieldSet } for
486
+ {responseName}; if no such set exists, create it as an empty set .
487
+ - Append all items in {fragmentGroup} to {fieldsForResponseName }.
488
+ - Return {groupedFieldSet }.
489
489
490
490
DoesFragmentTypeApply(objectType, fragmentType):
491
491
492
492
- If {fragmentType} is an Object Type:
493
493
- If {objectType} and {fragmentType} are the same type, return {true},
494
494
otherwise return {false}.
495
495
- If {fragmentType} is an Interface Type:
496
- - If {objectType} is an implementation of {fragmentType}, return {true}
496
+ - If {objectType} is an implementation of {fragmentType}, return {true},
497
497
otherwise return {false}.
498
498
- If {fragmentType} is a Union:
499
- - If {objectType} is a possible type of {fragmentType}, return {true}
499
+ - If {objectType} is a possible type of {fragmentType}, return {true},
500
500
otherwise return {false}.
501
501
502
502
Note: The steps in {CollectFields()} evaluating the ` @skip ` and ` @include `
503
503
directives may be applied in either order since they apply commutatively.
504
504
505
505
** Merging Selection Sets**
506
506
507
- When a field is executed, during value completion the _ selection set _ of each of
508
- the related field selections with the same response name are collected together
509
- to produce a single _ grouped field set_ in order to continue execution of the
510
- sub-selection sets .
507
+ In order to execute the sub-selections of a object typed field, all _ selection
508
+ sets _ of each field with the same response name of the parent _ field set _ are
509
+ merged together into a single _ grouped field set_ representing the subfields to
510
+ be executed next .
511
511
512
512
An example operation illustrating parallel fields with the same name with
513
513
sub-selections.
@@ -536,16 +536,16 @@ phase with the same value.
536
536
537
537
CollectSubfields(objectType, fields, variableValues):
538
538
539
- - Let {groupedFieldSet} be an empty map.
539
+ - Let {groupedFieldSet} be an empty ordered map of ordered sets .
540
540
- For each {field} in {fields}:
541
541
- Let {fieldSelectionSet} be the selection set of {field}.
542
542
- If {fieldSelectionSet} is null or empty, continue to the next field.
543
543
- Let {fieldGroupedFieldSet} be the result of {CollectFields(objectType,
544
544
fieldSelectionSet, variableValues)}.
545
545
- For each {fieldGroupedFieldSet} as {responseName} and {subfields}:
546
- - Let {groupForResponseName } be the list in {groupedFieldSet} for
547
- {responseName}; if no such list exists, create it as an empty list .
548
- - Append all fields in {subfields} to {groupForResponseName }.
546
+ - Let {fieldsForResponseName } be the _ field set _ in {groupedFieldSet} for
547
+ {responseName}; if no such set exists, create it as an empty set .
548
+ - Add each fields in {subfields} to {fieldsForResponseName }.
549
549
- Return {groupedFieldSet}.
550
550
551
551
Note: All the {fields} passed to {CollectSubfields()} share the same _ response
@@ -558,10 +558,8 @@ the field selections from a _selection set_ or the associated selection sets of
558
558
a _ field set_ respectively, and split them into groups by their _ response name_
559
559
to produce a _ grouped field set_ .
560
560
561
- To execute a _ grouped field set_ , the object value being evaluated and the
562
- object type need to be known, as well as whether it must be executed serially,
563
- or may be executed in parallel (see
564
- [ Normal and Serial Execution] ( #sec-Normal-and-Serial-Execution ) .
561
+ To execute a _ grouped field set_ , the object type being evaluated and the
562
+ runtime value need to be known, as well as the runtime values for any variables.
565
563
566
564
Each entry in the grouped field set represents a _ response name_ which produces
567
565
an entry into a result map.
0 commit comments