Basic Stitching Algorithm:
Execute Operation:
- Inline named fragments! This is done prior to coercing variables, so is done in a separate step. (should be done later? not at all?)
- Create a
RootPlanwith the transformed operation. - Create a node to hold the result.
- For each
SubschemaPlanin theRootPlan:- Send the initial set of operations.
- As each operation result becomes available, compose them:
- Create a
Stitchwith the help of the givenSubschemaPlanand a pointer to the result node. - Stitch the
Stitch.
- Create a
- Return the node.
Creating a RootPlan:
- Coerce variables.
- Apply skip/include directives (may depends on variables).
- Collects root fields based on the appropriate root type.
- Create a
FieldPlanfor the given root fields (with no base schema, such that theFieldTreefor theFieldPlanwill be empty). - Return the
FieldPlan.
Creating a FieldPlan:
- Let
fromSubschemabe the given base schema. - Create a data structure to hold the
FieldPlanwhich will contain theSubschemaPlans and theFieldTree. - For each provided field, add the given field to the
FieldPlanas follows:- Let
toSubschemabe the subschema from which this field should be retrieved. - Determine where in the data structure to add the field, creating a new
SubschemaPlanentry fortoSubschemaas necessary. - If the field has no sub-selections, add the field to the appropriate
SubschemaPlanand return. - Split the sub-selections in two, those that belong to
toSubschema, and those that don't. - Add the field with the sub-selections that belong to
toSubschemato the appropriateSubschemaPlan. - Create a
FieldPlanMapusing the sub-selections that do not belong to the subschema (withtoSubschemaas a base). - If
toSubschemais the same asfromSubschema, add theFieldPlanMapto theFieldPlan'sFieldTreeunder the response key for the field. - Otherwise, add the
FieldPlanMapto the appropriateSubschemaPlan'sFieldTreeunder the response key for the field.
- Let
- Return the
FieldPlan.
Creating a FieldPlanMap:
- Let
fromSubschemabe the given base schema. - Initialize a map of possible types to
FieldPlans. - For each possible type of this field:
- Collect the subfields from the sub-selections for the given type.
- Create the
FieldPlanfor the given subfields usingfromSubschema. - Within the map, set the entry for the given type to
FieldPlan.
- Return the map.
Result Composition (Stitching the Stitch):
- If the data section of the result is null, null the pointer node and return.
- Copy the
datafrom all the results under the pointer node. - Create a map of subschemas to
Stitches. - Walk the
FieldTreefor the givenSubschemaPlancreating newStitches for each subschema, updating the pointer as necessary, saving the stitches in the map. - Stitch the
Stitches.