relay-runtime 2.0.0-rc.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/lib/DataChecker.js +6 -0
- package/lib/RelayConcreteNode.js +2 -0
- package/lib/RelayModernEnvironment.js +18 -163
- package/lib/RelayModernQueryExecutor.js +172 -0
- package/lib/RelayModernStore.js +1 -1
- package/lib/RelayPublishQueue.js +9 -8
- package/lib/RelayReader.js +7 -4
- package/lib/RelayReferenceMarker.js +6 -0
- package/lib/RelayResponseNormalizer.js +75 -2
- package/lib/recycleNodesInto.js +16 -4
- package/lib/requestRelaySubscription.js +3 -1
- package/package.json +1 -1
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
+
var _toConsumableArray2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Normalizes the results of a query and standard GraphQL response, writing the
|
|
14
16
|
* normalized records/fields into the given MutableRecordSource.
|
|
@@ -39,7 +41,9 @@ function () {
|
|
|
39
41
|
function RelayResponseNormalizer(recordSource, variables, options) {
|
|
40
42
|
this._handleFieldPayloads = [];
|
|
41
43
|
this._handleStrippedNulls = options.handleStrippedNulls;
|
|
44
|
+
this._incrementalPayloads = [];
|
|
42
45
|
this._matchFieldPayloads = [];
|
|
46
|
+
this._path = options.path ? (0, _toConsumableArray2["default"])(options.path) : [];
|
|
43
47
|
this._recordSource = recordSource;
|
|
44
48
|
this._variables = variables;
|
|
45
49
|
}
|
|
@@ -54,6 +58,7 @@ function () {
|
|
|
54
58
|
this._traverseSelections(node, record, data);
|
|
55
59
|
|
|
56
60
|
return {
|
|
61
|
+
incrementalPayloads: this._incrementalPayloads,
|
|
57
62
|
fieldPayloads: this._handleFieldPayloads,
|
|
58
63
|
matchPayloads: this._matchFieldPayloads
|
|
59
64
|
};
|
|
@@ -105,6 +110,10 @@ function () {
|
|
|
105
110
|
});
|
|
106
111
|
} else if (selection.kind === require("./RelayConcreteNode").MATCH_FIELD) {
|
|
107
112
|
_this._normalizeMatchField(node, selection, record, data);
|
|
113
|
+
} else if (selection.kind === require("./RelayConcreteNode").DEFER) {
|
|
114
|
+
_this._normalizeDefer(selection, record, data);
|
|
115
|
+
} else if (selection.kind === require("./RelayConcreteNode").STREAM) {
|
|
116
|
+
_this._normalizeStream(selection, record, data);
|
|
108
117
|
} else if (selection.kind === require("./RelayConcreteNode").FRAGMENT || selection.kind === require("./RelayConcreteNode").FRAGMENT_SPREAD) {
|
|
109
118
|
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s`.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
|
|
110
119
|
} else {
|
|
@@ -114,6 +123,61 @@ function () {
|
|
|
114
123
|
});
|
|
115
124
|
};
|
|
116
125
|
|
|
126
|
+
_proto._normalizeDefer = function _normalizeDefer(defer, record, data) {
|
|
127
|
+
var isDeferred = defer["if"] === null || this._getVariableValue(defer["if"]);
|
|
128
|
+
|
|
129
|
+
if (process.env.NODE_ENV !== "production") {
|
|
130
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(typeof isDeferred === 'boolean', 'RelayResponseNormalizer: Expected value for @defer `if` argument to ' + 'be a boolean, got `%s`.', isDeferred) : void 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isDeferred === false) {
|
|
134
|
+
// If defer is disabled there will be no additional response chunk:
|
|
135
|
+
// normalize the data already present.
|
|
136
|
+
this._traverseSelections(defer, record, data);
|
|
137
|
+
} else {
|
|
138
|
+
// Otherwise data *for this selection* should not be present: enqueue
|
|
139
|
+
// metadata to process the subsequent response chunk.
|
|
140
|
+
this._incrementalPayloads.push({
|
|
141
|
+
kind: 'defer',
|
|
142
|
+
label: defer.label,
|
|
143
|
+
path: (0, _toConsumableArray2["default"])(this._path),
|
|
144
|
+
selector: {
|
|
145
|
+
dataID: require("./RelayModernRecord").getDataID(record),
|
|
146
|
+
node: defer,
|
|
147
|
+
variables: this._variables
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
_proto._normalizeStream = function _normalizeStream(stream, record, data) {
|
|
154
|
+
// Always normalize regardless of whether streaming is enabled or not,
|
|
155
|
+
// this populates the initial array value (including any items when
|
|
156
|
+
// initial_count > 0).
|
|
157
|
+
this._traverseSelections(stream, record, data);
|
|
158
|
+
|
|
159
|
+
var isStreamed = stream["if"] === null || this._getVariableValue(stream["if"]);
|
|
160
|
+
|
|
161
|
+
if (process.env.NODE_ENV !== "production") {
|
|
162
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(typeof isStreamed === 'boolean', 'RelayResponseNormalizer: Expected value for @stream `if` argument ' + 'to be a boolean, got `%s`.', isStreamed) : void 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (isStreamed === true) {
|
|
166
|
+
// If streaming is enabled, *also* emit metadata to process any
|
|
167
|
+
// response chunks that may be delivered.
|
|
168
|
+
this._incrementalPayloads.push({
|
|
169
|
+
kind: 'stream',
|
|
170
|
+
label: stream.label,
|
|
171
|
+
path: (0, _toConsumableArray2["default"])(this._path),
|
|
172
|
+
selector: {
|
|
173
|
+
dataID: require("./RelayModernRecord").getDataID(record),
|
|
174
|
+
node: stream,
|
|
175
|
+
variables: this._variables
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
117
181
|
_proto._normalizeMatchField = function _normalizeMatchField(parent, field, record, data) {
|
|
118
182
|
!(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeField(): Expected data for field `%s` to be an object.', field.name) : require("fbjs/lib/invariant")(false) : void 0;
|
|
119
183
|
var responseKey = field.alias || field.name;
|
|
@@ -170,9 +234,10 @@ function () {
|
|
|
170
234
|
|
|
171
235
|
if (operationReference != null) {
|
|
172
236
|
this._matchFieldPayloads.push({
|
|
173
|
-
operationReference: operationReference,
|
|
174
|
-
dataID: nextID,
|
|
175
237
|
data: fieldValue,
|
|
238
|
+
dataID: nextID,
|
|
239
|
+
operationReference: operationReference,
|
|
240
|
+
path: (0, _toConsumableArray2["default"])(this._path).concat([responseKey]),
|
|
176
241
|
typeName: typeName,
|
|
177
242
|
variables: this._variables
|
|
178
243
|
});
|
|
@@ -205,11 +270,15 @@ function () {
|
|
|
205
270
|
if (selection.kind === require("./RelayConcreteNode").SCALAR_FIELD) {
|
|
206
271
|
require("./RelayModernRecord").setValue(record, storageKey, fieldValue);
|
|
207
272
|
} else if (selection.kind === require("./RelayConcreteNode").LINKED_FIELD) {
|
|
273
|
+
this._path.push(responseKey);
|
|
274
|
+
|
|
208
275
|
if (selection.plural) {
|
|
209
276
|
this._normalizePluralLink(selection, record, storageKey, fieldValue);
|
|
210
277
|
} else {
|
|
211
278
|
this._normalizeLink(selection, record, storageKey, fieldValue);
|
|
212
279
|
}
|
|
280
|
+
|
|
281
|
+
this._path.pop();
|
|
213
282
|
} else if (selection.kind === require("./RelayConcreteNode").MATCH_FIELD) {
|
|
214
283
|
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s` during normalization.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
|
|
215
284
|
} else {
|
|
@@ -258,6 +327,8 @@ function () {
|
|
|
258
327
|
return;
|
|
259
328
|
}
|
|
260
329
|
|
|
330
|
+
_this2._path.push(String(nextIndex));
|
|
331
|
+
|
|
261
332
|
!(typeof item === 'object') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected elements for field `%s` to be ' + 'objects.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
|
262
333
|
|
|
263
334
|
var nextID = item.id || prevIDs && prevIDs[nextIndex] || // Reuse previously generated client IDs
|
|
@@ -279,6 +350,8 @@ function () {
|
|
|
279
350
|
}
|
|
280
351
|
|
|
281
352
|
_this2._traverseSelections(field, nextRecord, item);
|
|
353
|
+
|
|
354
|
+
_this2._path.pop();
|
|
282
355
|
});
|
|
283
356
|
|
|
284
357
|
require("./RelayModernRecord").setLinkedRecordIDs(record, storageKey, nextIDs);
|
package/lib/recycleNodesInto.js
CHANGED
|
@@ -28,10 +28,16 @@ function recycleNodesInto(prevData, nextData) {
|
|
|
28
28
|
var nextValue = recycleNodesInto(prevValue, nextItem);
|
|
29
29
|
|
|
30
30
|
if (nextValue !== nextArray[ii]) {
|
|
31
|
-
|
|
31
|
+
if (process.env.NODE_ENV !== "production") {
|
|
32
|
+
if (!Object.isFrozen(nextArray)) {
|
|
33
|
+
nextArray[ii] = nextValue;
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
nextArray[ii] = nextValue;
|
|
37
|
+
}
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
return wasEqual &&
|
|
40
|
+
return wasEqual && nextValue === prevArray[ii];
|
|
35
41
|
}, true) && prevArray.length === nextArray.length;
|
|
36
42
|
} else if (!prevArray && !nextArray) {
|
|
37
43
|
// Assign local variables to preserve Flow type refinement.
|
|
@@ -44,10 +50,16 @@ function recycleNodesInto(prevData, nextData) {
|
|
|
44
50
|
var nextValue = recycleNodesInto(prevValue, nextObject[key]);
|
|
45
51
|
|
|
46
52
|
if (nextValue !== nextObject[key]) {
|
|
47
|
-
|
|
53
|
+
if (process.env.NODE_ENV !== "production") {
|
|
54
|
+
if (!Object.isFrozen(nextObject)) {
|
|
55
|
+
nextObject[key] = nextValue;
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
nextObject[key] = nextValue;
|
|
59
|
+
}
|
|
48
60
|
}
|
|
49
61
|
|
|
50
|
-
return wasEqual &&
|
|
62
|
+
return wasEqual && nextValue === prevObject[key];
|
|
51
63
|
}, true) && prevKeys.length === nextKeys.length;
|
|
52
64
|
}
|
|
53
65
|
|
|
@@ -39,7 +39,9 @@ function requestRelaySubscription(environment, config) {
|
|
|
39
39
|
force: true
|
|
40
40
|
}
|
|
41
41
|
}).map(function () {
|
|
42
|
-
|
|
42
|
+
var data = environment.lookup(operation.fragment).data; // $FlowFixMe
|
|
43
|
+
|
|
44
|
+
return data;
|
|
43
45
|
}).subscribeLegacy({
|
|
44
46
|
onNext: onNext,
|
|
45
47
|
onError: onError,
|