Skip to content

Commit 625ff5d

Browse files
robrichardyaacovCR
authored andcommitted
Simplify execution, payloads should begin execution immediately
# Conflicts: # spec/Section 6 -- Execution.md
1 parent 147c3f0 commit 625ff5d

File tree

1 file changed

+34
-81
lines changed

1 file changed

+34
-81
lines changed

spec/Section 6 -- Execution.md

Lines changed: 34 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,13 @@ YieldSubsequentPayloads(subsequentPayloads):
380380
- While {subsequentPayloads} is not empty:
381381
- If a termination signal is received:
382382
- For each {record} in {subsequentPayloads}:
383-
- If {record} is a Stream Record:
384-
- Let {iterator} be the correspondent fields on the Stream Record
385-
structure.
383+
- If {record} contains {iterator}:
386384
- Send a termination signal to {iterator}.
387385
- Return.
388-
- Let {record} be the first complete item in {subsequentPayloads}.
386+
- Let {record} be the first item in {subsequentPayloads} with a completed
387+
{dataExecution}.
389388
- Remove {record} from {subsequentPayloads}.
390-
- Assert: {record} must be a Deferred Fragment Record or a Stream Record.
391-
- If {record} is a Deferred Fragment Record:
392-
- Let {payload} be the result of running
393-
{ResolveDeferredFragmentRecord(record, variableValues,
394-
subsequentPayloads)}.
395-
- If {record} is a Stream Record:
396-
- Let {payload} be the result of running {ResolveStreamRecord(record,
397-
variableValues, subsequentPayloads)}.
389+
- Let {payload} be the completed result returned by {dataExecution}.
398390
- If {payload} is {null}:
399391
- If {subsequentPayloads} is empty:
400392
- Yield a map containing a field `hasNext` with the value {false}.
@@ -626,10 +618,9 @@ subsequentPayloads, asyncRecord, visitedFragments):
626618
- If {deferDirective} is defined:
627619
- Let {label} be the value or the variable to {deferDirective}'s {label}
628620
argument.
629-
- Let {deferredFragmentRecord} be the result of calling
630-
{CreateDeferredFragmentRecord(label, objectType, objectValue,
631-
fragmentSelectionSet, path, asyncRecord)}.
632-
- Append {deferredFragmentRecord} to {subsequentPayloads}.
621+
- Call {ExecuteDeferredFragment(label, objectType, objectValue,
622+
fragmentSelectionSet, path, variableValues, asyncRecord,
623+
subsequentPayloads)}.
633624
- Continue with the next {selection} in {selectionSet}.
634625
- Let {fragmentGroupedFieldSet} be the result of calling
635626
{CollectFields(objectType, objectValue, fragmentSelectionSet,
@@ -652,10 +643,8 @@ subsequentPayloads, asyncRecord, visitedFragments):
652643
{variableValues} with the value {true}:
653644
- Let {label} be the value or the variable to {deferDirective}'s {label}
654645
argument.
655-
- Let {deferredFragmentRecord} be the result of calling
656-
{CreateDeferredFragmentRecord(label, objectType, objectValue,
657-
fragmentSelectionSet, path, asyncRecord)}.
658-
- Append {deferredFragmentRecord} to {subsequentPayloads}.
646+
- Call {ExecuteDeferredFragment(label, objectType, objectValue,
647+
fragmentSelectionSet, path, asyncRecord, subsequentPayloads)}.
659648
- Continue with the next {selection} in {selectionSet}.
660649
- Let {fragmentGroupedFieldSet} be the result of calling
661650
{CollectFields(objectType, objectValue, fragmentSelectionSet,
@@ -689,50 +678,31 @@ An Async Payload Record is either a Deferred Fragment Record or a Stream Record.
689678
All Async Payload Records are structures containing:
690679

691680
- {label}: value derived from the corresponding `@defer` or `@stream` directive.
692-
- {parentRecord}: optionally an Async Payload Record.
681+
- {path}: a list of field names and indices from root to the location of the
682+
corresponding `@defer` or `@stream` directive.
683+
- {iterator}: The underlying iterator if created from a `@stream` directive.
693684
- {errors}: a list of field errors encountered during execution.
694685
- {dataExecution}: A result that can notify when the corresponding execution has
695686
completed.
696-
- {path}: a list of field names and indices from root to the location of the
697-
corresponding `@defer` or `@stream` directive.
698-
699-
#### Deferred Fragment Record
700-
701-
Let {deferredFragmentRecord} be an inline fragment or fragment spread with
702-
`@defer` provided.
703-
704-
Deferred Fragment Record is a structure containing all the entries of Async
705-
Payload Record, and additionally:
706687

707-
- {objectType}: of the {deferredFragmentRecord}.
708-
- {objectValue}: of the {deferredFragmentRecord}.
709-
- {fragmentSelectionSet}: the top level selection set of
710-
{deferredFragmentRecord}.
688+
#### Execute Deferred Fragment
711689

712-
CreateDeferredFragmentRecord(label, objectType, objectValue,
713-
fragmentSelectionSet, path, parentRecord):
690+
ExecuteDeferredFragment(label, objectType, objectValue, fragmentSelectionSet,
691+
path, variableValues, parentRecord, subsequentPayloads):
714692

715-
- Construct a deferred fragment record based on the parameters passed in.
716-
- Initialize {errors} to an empty list.
717-
718-
ResolveDeferredFragmentRecord(deferredFragmentRecord, variableValues,
719-
subsequentPayloads):
720-
721-
- Let {label}, {objectType}, {objectValue}, {fragmentSelectionSet}, {path},
722-
{parentRecord} be the corresponding fields in the deferred fragment record
723-
structure.
693+
- Let {deferRecord} be an async payload record created from {label} and {path}.
694+
- Initialize {errors} on {deferRecord} to an empty list.
724695
- Let {dataExecution} be the asynchronous future value of:
725696
- Let {payload} be the result of {ExecuteSelectionSet(fragmentSelectionSet,
726697
objectType, objectValue, variableValues, path, subsequentPayloads,
727-
deferredFragmentRecord)}.
698+
deferRecord)}.
728699
- If {parentRecord} is defined:
729700
- Wait for the result of {dataExecution} on {parentRecord}.
701+
- Add an entry to {payload} named `label` with the value {label}.
702+
- Add an entry to {payload} named `path` with the value {path}.
730703
- Return {payload}.
731704
- Set {dataExecution} on {deferredFragmentRecord}.
732-
- Let {payload} be the result of waiting for {dataExecution}.
733-
- Add an entry to {payload} named `label` with the value {label}.
734-
- Add an entry to {payload} named `path` with the value {path}.
735-
- Return {payload}.
705+
- Append {deferRecord} to {subsequentPayloads}.
736706

737707
## Executing Fields
738708

@@ -876,28 +846,14 @@ field, value completion iterates over the iterator until the number of items
876846
yield by the iterator satisfies `initialCount` specified on the `@stream`
877847
directive.
878848

879-
#### Stream Record
880-
881-
Let {streamField} be a list field with a `@stream` directive provided.
882-
883-
A Stream Record is a structure containing all the entries of Async Payload
884-
Record, and additionally:
885-
886-
- {iterator}: created by {ResolveFieldGenerator}.
887-
- {index}: indicating the position of the item in the complete list.
888-
- {fields}: the group of fields grouped by CollectFields() for {streamField}.
889-
- {innerType}: inner type of {streamField}'s type.
890-
891-
CreateStreamRecord(label, iterator, index, fields, innerType, path,
892-
parentRecord):
893-
894-
- Construct a stream record based on the parameters passed in.
895-
- Initialize {errors} to an empty list.
849+
#### Execute Stream Field
896850

897-
ResolveStreamRecord(streamRecord, variableValues, subsequentPayloads):
851+
ExecuteStreamRecord(label, iterator, index, fields, innerType, path
852+
streamRecord, variableValues, subsequentPayloads):
898853

899-
- Let {label}, {parentRecord}, {iterator}, {index}, {path}, {fields},
900-
{innerType} be the correspondent fields on the Stream Record structure.
854+
- Let {streamRecord} be an async payload record created from {label}, {path},
855+
and {iterator}.
856+
- Initialize {errors} on {streamRecord} to an empty list.
901857
- Let {indexPath} be {path} with {index} appended.
902858
- Let {dataExecution} be the asynchronous future value of:
903859
- Wait for the next item from {iterator}.
@@ -907,17 +863,15 @@ ResolveStreamRecord(streamRecord, variableValues, subsequentPayloads):
907863
- Let {payload} be the result of calling {CompleteValue(innerType, fields,
908864
item, variableValues, indexPath, subsequentPayloads, parentRecord)}.
909865
- Increment {index}.
910-
- Let {nextStreamRecord} be the result of calling {CreateStreamRecord(label,
911-
iterator, index, fields, innerType, path, streamRecord)}.
912-
- Append {nextStreamRecord} to {subsequentPayloads}.
866+
- Call {ExecuteStreamRecord(label, iterator, index, fields, innerType, path,
867+
streamRecord, variableValues, subsequentPayloads)}.
913868
- If {parentRecord} is defined:
914869
- Wait for the result of {dataExecution} on {parentRecord}.
870+
- Add an entry to {payload} named `label` with the value {label}.
871+
- Add an entry to {payload} named `path` with the value {indexPath}.
915872
- Return {payload}.
916873
- Set {dataExecution} on {streamRecord}.
917-
- Let {payload} be the result of waiting for {dataExecution}.
918-
- Add an entry to {payload} named `label` with the value {label}.
919-
- Add an entry to {payload} named `path` with the value {indexPath}.
920-
- Return {payload}.
874+
- Append {streamRecord} to {subsequentPayloads}.
921875

922876
CompleteValue(fieldType, fields, result, variableValues, path,
923877
subsequentPayloads, asyncRecord):
@@ -955,9 +909,8 @@ subsequentPayloads, asyncRecord):
955909
- Increment {index}.
956910
- If {streamDirective} was provided and {index} is greater than or equal
957911
to {initialCount}:
958-
- Let {streamRecord} be the result of calling {CreateStreamRecord(label,
959-
result, index, fields, innerType, path, asyncRecord)}.
960-
- Append {streamRecord} to {subsequentPayloads}.
912+
- Call {ExecuteStreamRecord(label, result, index, fields, innerType,
913+
path, asyncRecord, subsequentPayloads)}.
961914
- Let {result} be {initialItems}.
962915
- Exit while loop.
963916
- Return {initialItems}.

0 commit comments

Comments
 (0)