Created
October 25, 2022 14:35
-
-
Save alloy/ab6b1ffca8c615bd699887d0a94e324a to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/node_modules/relay-runtime/lib/store/RelayResponseNormalizer.js b/node_modules/relay-runtime/lib/store/RelayResponseNormalizer.js | |
index b9994b3..e970570 100644 | |
--- a/node_modules/relay-runtime/lib/store/RelayResponseNormalizer.js | |
+++ b/node_modules/relay-runtime/lib/store/RelayResponseNormalizer.js | |
@@ -351,6 +351,7 @@ var RelayResponseNormalizer = /*#__PURE__*/function () { | |
if (process.env.NODE_ENV !== "production") { | |
process.env.NODE_ENV !== "production" ? warning(typeof isDeferred === 'boolean', 'RelayResponseNormalizer: Expected value for @defer `if` argument to ' + 'be a boolean, got `%s`.', isDeferred) : void 0; | |
+ invariant(defer.selections[0].kind === "InlineFragment" && defer.selections[0].selections.length > 0, "RelayResponseNormalizer: Expected @defer on InlineFragment with selections"); | |
} | |
if (isDeferred === false) { | |
@@ -358,17 +359,25 @@ var RelayResponseNormalizer = /*#__PURE__*/function () { | |
// normalize the data already present. | |
this._traverseSelections(defer, record, data); | |
} else { | |
- // Otherwise data *for this selection* should not be present: enqueue | |
- // metadata to process the subsequent response chunk. | |
- this._incrementalPlaceholders.push({ | |
- kind: 'defer', | |
- data: data, | |
- label: defer.label, | |
- path: (0, _toConsumableArray2["default"])(this._path), | |
- selector: createNormalizationSelector(defer, RelayModernRecord.getDataID(record), this._variables), | |
- typeName: RelayModernRecord.getType(record), | |
- actorIdentifier: this._actorIdentifier | |
- }); | |
+ const isDeferredDataPresent = defer.selections[0].selections.every(sel => data[sel.name] !== undefined); | |
+ if (isDeferredDataPresent) { | |
+ // According to the spec, clients should use deferred data in the | |
+ // initial response, if it exists: | |
+ // https://github.com/graphql/graphql-spec/pull/742#discussion_r993838228 | |
+ this._traverseSelections(defer, record, data); | |
+ } else { | |
+ // Otherwise data *for this selection* should not be present: enqueue | |
+ // metadata to process the subsequent response chunk. | |
+ this._incrementalPlaceholders.push({ | |
+ kind: 'defer', | |
+ data: data, | |
+ label: defer.label, | |
+ path: (0, _toConsumableArray2["default"])(this._path), | |
+ selector: createNormalizationSelector(defer, RelayModernRecord.getDataID(record), this._variables), | |
+ typeName: RelayModernRecord.getType(record), | |
+ actorIdentifier: this._actorIdentifier | |
+ }); | |
+ } | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment