relay-runtime 1.7.0-rc.1 → 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/LICENSE +1 -1
- package/index.js +1 -1
- package/lib/ConvertToExecuteFunction.js +12 -75
- package/lib/DataChecker.js +400 -0
- package/lib/NormalizationNode.js +14 -0
- package/lib/ReaderNode.js +10 -0
- package/lib/RelayCombinedEnvironmentTypes.js +10 -0
- package/lib/RelayConcreteNode.js +12 -29
- package/lib/RelayConcreteVariables.js +17 -11
- package/lib/RelayConnectionHandler.js +98 -42
- package/lib/RelayConnectionInterface.js +5 -13
- package/lib/RelayCore.js +17 -14
- package/lib/RelayDeclarativeMutationConfig.js +69 -34
- package/lib/RelayDefaultHandleKey.js +1 -2
- package/lib/RelayDefaultHandlerProvider.js +6 -5
- package/lib/RelayError.js +6 -9
- package/lib/RelayInMemoryRecordSource.js +20 -22
- package/lib/RelayModernEnvironment.js +140 -229
- package/lib/RelayModernFragmentSpecResolver.js +110 -102
- package/lib/RelayModernGraphQLTag.js +53 -15
- package/lib/{RelayModernOperationSelector.js → RelayModernOperationDescriptor.js} +9 -8
- package/lib/RelayModernQueryExecutor.js +172 -0
- package/lib/RelayModernRecord.js +97 -38
- package/lib/RelayModernSelector.js +89 -33
- package/lib/RelayModernStore.js +301 -0
- package/lib/RelayNetwork.js +16 -28
- package/lib/RelayNetworkLogger.js +2 -3
- package/lib/RelayNetworkLoggerTransaction.js +32 -30
- package/lib/RelayNetworkTypes.js +1 -2
- package/lib/RelayObservable.js +127 -155
- package/lib/RelayProfiler.js +35 -22
- package/lib/RelayPublishQueue.js +144 -96
- package/lib/RelayQueryResponseCache.js +37 -21
- package/lib/RelayReader.js +194 -61
- package/lib/RelayRecordProxy.js +50 -31
- package/lib/RelayRecordSourceMutator.js +92 -51
- package/lib/RelayRecordSourceProxy.js +43 -35
- package/lib/RelayRecordSourceSelectorProxy.js +22 -21
- package/lib/RelayRecordState.js +1 -3
- package/lib/RelayReferenceMarker.js +110 -37
- package/lib/RelayResponseNormalizer.js +248 -82
- package/lib/RelayRuntimeTypes.js +1 -3
- package/lib/RelayStoreTypes.js +1 -2
- package/lib/RelayStoreUtils.js +37 -19
- package/lib/RelayViewerHandler.js +14 -10
- package/lib/applyRelayModernOptimisticMutation.js +8 -8
- package/lib/cloneRelayHandleSourceField.js +8 -9
- package/lib/commitLocalUpdate.js +1 -2
- package/lib/commitRelayModernMutation.js +21 -14
- package/lib/createRelayNetworkLogger.js +11 -9
- package/lib/deepFreeze.js +2 -3
- package/lib/fetchRelayModernQuery.js +10 -12
- package/lib/generateRelayClientID.js +4 -2
- package/lib/getRelayHandleKey.js +5 -6
- package/lib/hasOverlappingIDs.js +3 -2
- package/lib/index.js +59 -62
- package/lib/isPromise.js +1 -2
- package/lib/isRelayModernEnvironment.js +1 -3
- package/lib/isScalarAndEqual.js +1 -3
- package/lib/normalizePayload.js +17 -15
- package/lib/normalizeRelayPayload.js +9 -9
- package/lib/recycleNodesInto.js +25 -9
- package/lib/requestRelaySubscription.js +25 -58
- package/lib/simpleClone.js +2 -3
- package/lib/stableCopy.js +5 -3
- package/lib/validateMutation.js +146 -0
- package/package.json +3 -3
- package/relay-runtime.js +4 -0
- package/relay-runtime.min.js +9 -0
- package/lib/RelayDataLoader.js +0 -302
- package/lib/RelayMarkSweepStore.js +0 -242
- package/lib/deferrableFragmentKey.js +0 -20
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -7,12 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
12
|
+
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
|
16
13
|
|
|
17
14
|
/**
|
|
18
15
|
* Determines the variables that are in scope for a fragment given the variables
|
|
@@ -22,16 +19,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
|
|
|
22
19
|
* Note that this is analagous to determining function arguments given a function call.
|
|
23
20
|
*/
|
|
24
21
|
function getFragmentVariables(fragment, rootVariables, argumentVariables) {
|
|
25
|
-
var variables
|
|
22
|
+
var variables;
|
|
26
23
|
fragment.argumentDefinitions.forEach(function (definition) {
|
|
27
24
|
if (argumentVariables.hasOwnProperty(definition.name)) {
|
|
28
25
|
return;
|
|
29
26
|
}
|
|
30
|
-
|
|
27
|
+
|
|
28
|
+
variables = variables || (0, _objectSpread2["default"])({}, argumentVariables);
|
|
29
|
+
|
|
31
30
|
switch (definition.kind) {
|
|
32
31
|
case 'LocalArgument':
|
|
33
32
|
variables[definition.name] = definition.defaultValue;
|
|
34
33
|
break;
|
|
34
|
+
|
|
35
35
|
case 'RootArgument':
|
|
36
36
|
if (!rootVariables.hasOwnProperty(definition.name)) {
|
|
37
37
|
/*
|
|
@@ -41,31 +41,37 @@ function getFragmentVariables(fragment, rootVariables, argumentVariables) {
|
|
|
41
41
|
*/
|
|
42
42
|
break;
|
|
43
43
|
}
|
|
44
|
+
|
|
44
45
|
variables[definition.name] = rootVariables[definition.name];
|
|
45
46
|
break;
|
|
47
|
+
|
|
46
48
|
default:
|
|
47
|
-
!false ? process.env.NODE_ENV !==
|
|
49
|
+
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayConcreteVariables: Unexpected node kind `%s` in fragment `%s`.', definition.kind, fragment.name) : require("fbjs/lib/invariant")(false) : void 0;
|
|
48
50
|
}
|
|
49
51
|
});
|
|
50
52
|
return variables || argumentVariables;
|
|
51
53
|
}
|
|
52
|
-
|
|
53
54
|
/**
|
|
54
55
|
* Determines the variables that are in scope for a given operation given values
|
|
55
56
|
* for some/all of its arguments. Extraneous input variables are filtered from
|
|
56
57
|
* the output, and missing variables are set to default values (if given in the
|
|
57
58
|
* operation's definition).
|
|
58
59
|
*/
|
|
60
|
+
|
|
61
|
+
|
|
59
62
|
function getOperationVariables(operation, variables) {
|
|
60
63
|
var operationVariables = {};
|
|
61
64
|
operation.argumentDefinitions.forEach(function (def) {
|
|
62
65
|
var value = def.defaultValue;
|
|
66
|
+
|
|
63
67
|
if (variables[def.name] != null) {
|
|
64
68
|
value = variables[def.name];
|
|
65
69
|
}
|
|
70
|
+
|
|
66
71
|
operationVariables[def.name] = value;
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
|
|
73
|
+
if (process.env.NODE_ENV !== "production") {
|
|
74
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(value != null || def.type[def.type.length - 1] !== '!', 'RelayConcreteVariables: Expected a value for non-nullable variable ' + '`$%s: %s` on operation `%s`, got `%s`. Make sure you supply a ' + 'value for all non-nullable arguments.', def.name, def.type, operation.name, JSON.stringify(value)) : void 0;
|
|
69
75
|
}
|
|
70
76
|
});
|
|
71
77
|
return operationVariables;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -7,14 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
var CONNECTION = 'connection';
|
|
12
|
+
var CONNECTION = 'connection'; // Per-instance incrementing index used to generate unique edge IDs
|
|
14
13
|
|
|
15
|
-
// Per-instance incrementing index used to generate unique edge IDs
|
|
16
14
|
var NEXT_EDGE_INDEX = '__connection_next_edge_index';
|
|
17
|
-
|
|
18
15
|
/**
|
|
19
16
|
* @public
|
|
20
17
|
*
|
|
@@ -22,13 +19,15 @@ var NEXT_EDGE_INDEX = '__connection_next_edge_index';
|
|
|
22
19
|
* edges onto the end of a connection, regardless of the arguments used to fetch
|
|
23
20
|
* those edges.
|
|
24
21
|
*/
|
|
22
|
+
|
|
25
23
|
function update(store, payload) {
|
|
26
24
|
var record = store.get(payload.dataID);
|
|
25
|
+
|
|
27
26
|
if (!record) {
|
|
28
27
|
return;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
var _RelayConnectionInter = require(
|
|
30
|
+
var _RelayConnectionInter = require("./RelayConnectionInterface").get(),
|
|
32
31
|
EDGES = _RelayConnectionInter.EDGES,
|
|
33
32
|
END_CURSOR = _RelayConnectionInter.END_CURSOR,
|
|
34
33
|
HAS_NEXT_PAGE = _RelayConnectionInter.HAS_NEXT_PAGE,
|
|
@@ -39,60 +38,73 @@ function update(store, payload) {
|
|
|
39
38
|
|
|
40
39
|
var serverConnection = record.getLinkedRecord(payload.fieldKey);
|
|
41
40
|
var serverPageInfo = serverConnection && serverConnection.getLinkedRecord(PAGE_INFO);
|
|
41
|
+
|
|
42
42
|
if (!serverConnection) {
|
|
43
43
|
record.setValue(null, payload.handleKey);
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
+
|
|
46
47
|
var clientConnection = record.getLinkedRecord(payload.handleKey);
|
|
47
48
|
var clientPageInfo = clientConnection && clientConnection.getLinkedRecord(PAGE_INFO);
|
|
49
|
+
|
|
48
50
|
if (!clientConnection) {
|
|
49
51
|
// Initial fetch with data: copy fields from the server record
|
|
50
|
-
var connection = store.create(require(
|
|
52
|
+
var connection = store.create(require("./generateRelayClientID")(record.getDataID(), payload.handleKey), serverConnection.getType());
|
|
51
53
|
connection.setValue(0, NEXT_EDGE_INDEX);
|
|
52
54
|
connection.copyFieldsFrom(serverConnection);
|
|
53
55
|
var serverEdges = serverConnection.getLinkedRecords(EDGES);
|
|
56
|
+
|
|
54
57
|
if (serverEdges) {
|
|
55
58
|
serverEdges = serverEdges.map(function (edge) {
|
|
56
59
|
return buildConnectionEdge(store, connection, edge);
|
|
57
60
|
});
|
|
58
61
|
connection.setLinkedRecords(serverEdges, EDGES);
|
|
59
62
|
}
|
|
60
|
-
record.setLinkedRecord(connection, payload.handleKey);
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
record.setLinkedRecord(connection, payload.handleKey);
|
|
65
|
+
clientPageInfo = store.create(require("./generateRelayClientID")(connection.getDataID(), PAGE_INFO), PAGE_INFO_TYPE);
|
|
63
66
|
clientPageInfo.setValue(false, HAS_NEXT_PAGE);
|
|
64
67
|
clientPageInfo.setValue(false, HAS_PREV_PAGE);
|
|
65
68
|
clientPageInfo.setValue(null, END_CURSOR);
|
|
66
69
|
clientPageInfo.setValue(null, START_CURSOR);
|
|
70
|
+
|
|
67
71
|
if (serverPageInfo) {
|
|
68
72
|
clientPageInfo.copyFieldsFrom(serverPageInfo);
|
|
69
73
|
}
|
|
74
|
+
|
|
70
75
|
connection.setLinkedRecord(clientPageInfo, PAGE_INFO);
|
|
71
76
|
} else {
|
|
72
|
-
var _connection = clientConnection;
|
|
73
|
-
// Subsequent fetches:
|
|
77
|
+
var _connection = clientConnection; // Subsequent fetches:
|
|
74
78
|
// - updated fields on the connection
|
|
75
79
|
// - merge prev/next edges, de-duplicating by node id
|
|
76
80
|
// - synthesize page info fields
|
|
81
|
+
|
|
77
82
|
var _serverEdges = serverConnection.getLinkedRecords(EDGES);
|
|
83
|
+
|
|
78
84
|
if (_serverEdges) {
|
|
79
85
|
_serverEdges = _serverEdges.map(function (edge) {
|
|
80
86
|
return buildConnectionEdge(store, _connection, edge);
|
|
81
87
|
});
|
|
82
88
|
}
|
|
89
|
+
|
|
83
90
|
var prevEdges = _connection.getLinkedRecords(EDGES);
|
|
91
|
+
|
|
84
92
|
var prevPageInfo = _connection.getLinkedRecord(PAGE_INFO);
|
|
85
|
-
|
|
86
|
-
// Reset EDGES and PAGE_INFO fields
|
|
93
|
+
|
|
94
|
+
_connection.copyFieldsFrom(serverConnection); // Reset EDGES and PAGE_INFO fields
|
|
95
|
+
|
|
96
|
+
|
|
87
97
|
if (prevEdges) {
|
|
88
98
|
_connection.setLinkedRecords(prevEdges, EDGES);
|
|
89
99
|
}
|
|
100
|
+
|
|
90
101
|
if (prevPageInfo) {
|
|
91
102
|
_connection.setLinkedRecord(prevPageInfo, PAGE_INFO);
|
|
92
103
|
}
|
|
93
104
|
|
|
94
105
|
var nextEdges = [];
|
|
95
106
|
var args = payload.args;
|
|
107
|
+
|
|
96
108
|
if (prevEdges && _serverEdges) {
|
|
97
109
|
if (args.after != null) {
|
|
98
110
|
// Forward pagination from the end of the connection: append edges
|
|
@@ -101,17 +113,18 @@ function update(store, payload) {
|
|
|
101
113
|
mergeEdges(prevEdges, nextEdges, nodeIDs);
|
|
102
114
|
mergeEdges(_serverEdges, nextEdges, nodeIDs);
|
|
103
115
|
} else {
|
|
104
|
-
process.env.NODE_ENV !==
|
|
116
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayConnectionHandler: Unexpected after cursor `%s`, edges must ' + 'be fetched from the end of the list (`%s`).', args.after, clientPageInfo && clientPageInfo.getValue(END_CURSOR)) : void 0;
|
|
105
117
|
return;
|
|
106
118
|
}
|
|
107
119
|
} else if (args.before != null) {
|
|
108
120
|
// Backward pagination from the start of the connection: prepend edges
|
|
109
121
|
if (clientPageInfo && args.before === clientPageInfo.getValue(START_CURSOR)) {
|
|
110
122
|
var _nodeIDs = new Set();
|
|
123
|
+
|
|
111
124
|
mergeEdges(_serverEdges, nextEdges, _nodeIDs);
|
|
112
125
|
mergeEdges(prevEdges, nextEdges, _nodeIDs);
|
|
113
126
|
} else {
|
|
114
|
-
process.env.NODE_ENV !==
|
|
127
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayConnectionHandler: Unexpected before cursor `%s`, edges must ' + 'be fetched from the beginning of the list (`%s`).', args.before, clientPageInfo && clientPageInfo.getValue(START_CURSOR)) : void 0;
|
|
115
128
|
return;
|
|
116
129
|
}
|
|
117
130
|
} else {
|
|
@@ -122,13 +135,15 @@ function update(store, payload) {
|
|
|
122
135
|
nextEdges = _serverEdges;
|
|
123
136
|
} else {
|
|
124
137
|
nextEdges = prevEdges;
|
|
125
|
-
}
|
|
126
|
-
// Update edges only if they were updated, the null check is
|
|
138
|
+
} // Update edges only if they were updated, the null check is
|
|
127
139
|
// for Flow (prevEdges could be null).
|
|
140
|
+
|
|
141
|
+
|
|
128
142
|
if (nextEdges != null && nextEdges !== prevEdges) {
|
|
129
143
|
_connection.setLinkedRecords(nextEdges, EDGES);
|
|
130
|
-
}
|
|
131
|
-
|
|
144
|
+
} // Page info should be updated even if no new edge were returned.
|
|
145
|
+
|
|
146
|
+
|
|
132
147
|
if (clientPageInfo && serverPageInfo) {
|
|
133
148
|
if (args.after == null && args.before == null) {
|
|
134
149
|
// The connection was refetched from the beginning/end: replace
|
|
@@ -137,12 +152,14 @@ function update(store, payload) {
|
|
|
137
152
|
} else if (args.before != null || args.after == null && args.last) {
|
|
138
153
|
clientPageInfo.setValue(!!serverPageInfo.getValue(HAS_PREV_PAGE), HAS_PREV_PAGE);
|
|
139
154
|
var startCursor = serverPageInfo.getValue(START_CURSOR);
|
|
155
|
+
|
|
140
156
|
if (typeof startCursor === 'string') {
|
|
141
157
|
clientPageInfo.setValue(startCursor, START_CURSOR);
|
|
142
158
|
}
|
|
143
159
|
} else if (args.after != null || args.before == null && args.first) {
|
|
144
160
|
clientPageInfo.setValue(!!serverPageInfo.getValue(HAS_NEXT_PAGE), HAS_NEXT_PAGE);
|
|
145
161
|
var endCursor = serverPageInfo.getValue(END_CURSOR);
|
|
162
|
+
|
|
146
163
|
if (typeof endCursor === 'string') {
|
|
147
164
|
clientPageInfo.setValue(endCursor, END_CURSOR);
|
|
148
165
|
}
|
|
@@ -150,7 +167,6 @@ function update(store, payload) {
|
|
|
150
167
|
}
|
|
151
168
|
}
|
|
152
169
|
}
|
|
153
|
-
|
|
154
170
|
/**
|
|
155
171
|
* @public
|
|
156
172
|
*
|
|
@@ -189,11 +205,13 @@ function update(store, payload) {
|
|
|
189
205
|
* Currently we haven't run into this case yet, but we need to add a `getConnections`
|
|
190
206
|
* that returns an array of the connections under the same `key` regardless of the variables.
|
|
191
207
|
*/
|
|
208
|
+
|
|
209
|
+
|
|
192
210
|
function getConnection(record, key, filters) {
|
|
193
|
-
var handleKey = require(
|
|
211
|
+
var handleKey = require("./getRelayHandleKey")(CONNECTION, key, null);
|
|
212
|
+
|
|
194
213
|
return record.getLinkedRecord(handleKey, filters);
|
|
195
214
|
}
|
|
196
|
-
|
|
197
215
|
/**
|
|
198
216
|
* @public
|
|
199
217
|
*
|
|
@@ -228,51 +246,61 @@ function getConnection(record, key, filters) {
|
|
|
228
246
|
* }
|
|
229
247
|
* ```
|
|
230
248
|
*/
|
|
249
|
+
|
|
250
|
+
|
|
231
251
|
function insertEdgeAfter(record, newEdge, cursor) {
|
|
232
|
-
var _RelayConnectionInter2 = require(
|
|
252
|
+
var _RelayConnectionInter2 = require("./RelayConnectionInterface").get(),
|
|
233
253
|
CURSOR = _RelayConnectionInter2.CURSOR,
|
|
234
254
|
EDGES = _RelayConnectionInter2.EDGES;
|
|
235
255
|
|
|
236
256
|
var edges = record.getLinkedRecords(EDGES);
|
|
257
|
+
|
|
237
258
|
if (!edges) {
|
|
238
259
|
record.setLinkedRecords([newEdge], EDGES);
|
|
239
260
|
return;
|
|
240
261
|
}
|
|
241
|
-
|
|
262
|
+
|
|
263
|
+
var nextEdges;
|
|
264
|
+
|
|
242
265
|
if (cursor == null) {
|
|
243
266
|
nextEdges = edges.concat(newEdge);
|
|
244
267
|
} else {
|
|
245
268
|
nextEdges = [];
|
|
246
269
|
var foundCursor = false;
|
|
270
|
+
|
|
247
271
|
for (var ii = 0; ii < edges.length; ii++) {
|
|
248
272
|
var edge = edges[ii];
|
|
249
273
|
nextEdges.push(edge);
|
|
274
|
+
|
|
250
275
|
if (edge == null) {
|
|
251
276
|
continue;
|
|
252
277
|
}
|
|
278
|
+
|
|
253
279
|
var edgeCursor = edge.getValue(CURSOR);
|
|
280
|
+
|
|
254
281
|
if (cursor === edgeCursor) {
|
|
255
282
|
nextEdges.push(newEdge);
|
|
256
283
|
foundCursor = true;
|
|
257
284
|
}
|
|
258
285
|
}
|
|
286
|
+
|
|
259
287
|
if (!foundCursor) {
|
|
260
288
|
nextEdges.push(newEdge);
|
|
261
289
|
}
|
|
262
290
|
}
|
|
291
|
+
|
|
263
292
|
record.setLinkedRecords(nextEdges, EDGES);
|
|
264
293
|
}
|
|
265
|
-
|
|
266
294
|
/**
|
|
267
295
|
* @public
|
|
268
296
|
*
|
|
269
297
|
* Creates an edge for a connection record, given a node and edge type.
|
|
270
298
|
*/
|
|
271
|
-
function createEdge(store, record, node, edgeType) {
|
|
272
|
-
var _RelayConnectionInter3 = require('./RelayConnectionInterface').get(),
|
|
273
|
-
NODE = _RelayConnectionInter3.NODE;
|
|
274
299
|
|
|
275
|
-
|
|
300
|
+
|
|
301
|
+
function createEdge(store, record, node, edgeType) {
|
|
302
|
+
var _RelayConnectionInter3 = require("./RelayConnectionInterface").get(),
|
|
303
|
+
NODE = _RelayConnectionInter3.NODE; // An index-based client ID could easily conflict (unless it was
|
|
276
304
|
// auto-incrementing, but there is nowhere to the store the id)
|
|
277
305
|
// Instead, construct a client ID based on the connection ID and node ID,
|
|
278
306
|
// which will only conflict if the same node is added to the same connection
|
|
@@ -280,15 +308,17 @@ function createEdge(store, record, node, edgeType) {
|
|
|
280
308
|
// duplicates.
|
|
281
309
|
|
|
282
310
|
|
|
283
|
-
var edgeID = require(
|
|
311
|
+
var edgeID = require("./generateRelayClientID")(record.getDataID(), node.getDataID());
|
|
312
|
+
|
|
284
313
|
var edge = store.get(edgeID);
|
|
314
|
+
|
|
285
315
|
if (!edge) {
|
|
286
316
|
edge = store.create(edgeID, edgeType);
|
|
287
317
|
}
|
|
318
|
+
|
|
288
319
|
edge.setLinkedRecord(node, NODE);
|
|
289
320
|
return edge;
|
|
290
321
|
}
|
|
291
|
-
|
|
292
322
|
/**
|
|
293
323
|
* @public
|
|
294
324
|
*
|
|
@@ -323,58 +353,74 @@ function createEdge(store, record, node, edgeType) {
|
|
|
323
353
|
* }
|
|
324
354
|
* ```
|
|
325
355
|
*/
|
|
356
|
+
|
|
357
|
+
|
|
326
358
|
function insertEdgeBefore(record, newEdge, cursor) {
|
|
327
|
-
var _RelayConnectionInter4 = require(
|
|
359
|
+
var _RelayConnectionInter4 = require("./RelayConnectionInterface").get(),
|
|
328
360
|
CURSOR = _RelayConnectionInter4.CURSOR,
|
|
329
361
|
EDGES = _RelayConnectionInter4.EDGES;
|
|
330
362
|
|
|
331
363
|
var edges = record.getLinkedRecords(EDGES);
|
|
364
|
+
|
|
332
365
|
if (!edges) {
|
|
333
366
|
record.setLinkedRecords([newEdge], EDGES);
|
|
334
367
|
return;
|
|
335
368
|
}
|
|
336
|
-
|
|
369
|
+
|
|
370
|
+
var nextEdges;
|
|
371
|
+
|
|
337
372
|
if (cursor == null) {
|
|
338
373
|
nextEdges = [newEdge].concat(edges);
|
|
339
374
|
} else {
|
|
340
375
|
nextEdges = [];
|
|
341
376
|
var foundCursor = false;
|
|
377
|
+
|
|
342
378
|
for (var ii = 0; ii < edges.length; ii++) {
|
|
343
379
|
var edge = edges[ii];
|
|
380
|
+
|
|
344
381
|
if (edge != null) {
|
|
345
382
|
var edgeCursor = edge.getValue(CURSOR);
|
|
383
|
+
|
|
346
384
|
if (cursor === edgeCursor) {
|
|
347
385
|
nextEdges.push(newEdge);
|
|
348
386
|
foundCursor = true;
|
|
349
387
|
}
|
|
350
388
|
}
|
|
389
|
+
|
|
351
390
|
nextEdges.push(edge);
|
|
352
391
|
}
|
|
392
|
+
|
|
353
393
|
if (!foundCursor) {
|
|
354
394
|
nextEdges.unshift(newEdge);
|
|
355
395
|
}
|
|
356
396
|
}
|
|
397
|
+
|
|
357
398
|
record.setLinkedRecords(nextEdges, EDGES);
|
|
358
399
|
}
|
|
359
|
-
|
|
360
400
|
/**
|
|
361
401
|
* @public
|
|
362
402
|
*
|
|
363
403
|
* Remove any edges whose `node.id` matches the given id.
|
|
364
404
|
*/
|
|
405
|
+
|
|
406
|
+
|
|
365
407
|
function deleteNode(record, nodeID) {
|
|
366
|
-
var _RelayConnectionInter5 = require(
|
|
408
|
+
var _RelayConnectionInter5 = require("./RelayConnectionInterface").get(),
|
|
367
409
|
EDGES = _RelayConnectionInter5.EDGES,
|
|
368
410
|
NODE = _RelayConnectionInter5.NODE;
|
|
369
411
|
|
|
370
412
|
var edges = record.getLinkedRecords(EDGES);
|
|
413
|
+
|
|
371
414
|
if (!edges) {
|
|
372
415
|
return;
|
|
373
416
|
}
|
|
374
|
-
|
|
417
|
+
|
|
418
|
+
var nextEdges;
|
|
419
|
+
|
|
375
420
|
for (var ii = 0; ii < edges.length; ii++) {
|
|
376
421
|
var edge = edges[ii];
|
|
377
422
|
var node = edge && edge.getLinkedRecord(NODE);
|
|
423
|
+
|
|
378
424
|
if (node != null && node.getDataID() === nodeID) {
|
|
379
425
|
if (nextEdges === undefined) {
|
|
380
426
|
nextEdges = edges.slice(0, ii);
|
|
@@ -383,11 +429,11 @@ function deleteNode(record, nodeID) {
|
|
|
383
429
|
nextEdges.push(edge);
|
|
384
430
|
}
|
|
385
431
|
}
|
|
432
|
+
|
|
386
433
|
if (nextEdges !== undefined) {
|
|
387
434
|
record.setLinkedRecords(nextEdges, EDGES);
|
|
388
435
|
}
|
|
389
436
|
}
|
|
390
|
-
|
|
391
437
|
/**
|
|
392
438
|
* @internal
|
|
393
439
|
*
|
|
@@ -401,46 +447,56 @@ function deleteNode(record, nodeID) {
|
|
|
401
447
|
* though the nodes they point to may be different (or the same and in different
|
|
402
448
|
* order).
|
|
403
449
|
*/
|
|
450
|
+
|
|
451
|
+
|
|
404
452
|
function buildConnectionEdge(store, connection, edge) {
|
|
405
453
|
if (edge == null) {
|
|
406
454
|
return edge;
|
|
407
455
|
}
|
|
408
456
|
|
|
409
|
-
var _RelayConnectionInter6 = require(
|
|
457
|
+
var _RelayConnectionInter6 = require("./RelayConnectionInterface").get(),
|
|
410
458
|
EDGES = _RelayConnectionInter6.EDGES;
|
|
411
459
|
|
|
412
460
|
var edgeIndex = connection.getValue(NEXT_EDGE_INDEX);
|
|
413
|
-
!(typeof edgeIndex === 'number') ? process.env.NODE_ENV !==
|
|
414
|
-
|
|
461
|
+
!(typeof edgeIndex === 'number') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayConnectionHandler: Expected %s to be a number, got `%s`.', NEXT_EDGE_INDEX, edgeIndex) : require("fbjs/lib/invariant")(false) : void 0;
|
|
462
|
+
|
|
463
|
+
var edgeID = require("./generateRelayClientID")(connection.getDataID(), EDGES, edgeIndex);
|
|
464
|
+
|
|
415
465
|
var connectionEdge = store.create(edgeID, edge.getType());
|
|
416
466
|
connectionEdge.copyFieldsFrom(edge);
|
|
417
467
|
connection.setValue(edgeIndex + 1, NEXT_EDGE_INDEX);
|
|
418
468
|
return connectionEdge;
|
|
419
469
|
}
|
|
420
|
-
|
|
421
470
|
/**
|
|
422
471
|
* @internal
|
|
423
472
|
*
|
|
424
473
|
* Adds the source edges to the target edges, skipping edges with
|
|
425
474
|
* duplicate node ids.
|
|
426
475
|
*/
|
|
476
|
+
|
|
477
|
+
|
|
427
478
|
function mergeEdges(sourceEdges, targetEdges, nodeIDs) {
|
|
428
|
-
var _RelayConnectionInter7 = require(
|
|
479
|
+
var _RelayConnectionInter7 = require("./RelayConnectionInterface").get(),
|
|
429
480
|
NODE = _RelayConnectionInter7.NODE;
|
|
430
481
|
|
|
431
482
|
for (var ii = 0; ii < sourceEdges.length; ii++) {
|
|
432
483
|
var edge = sourceEdges[ii];
|
|
484
|
+
|
|
433
485
|
if (!edge) {
|
|
434
486
|
continue;
|
|
435
487
|
}
|
|
488
|
+
|
|
436
489
|
var node = edge.getLinkedRecord(NODE);
|
|
437
490
|
var nodeID = node && node.getValue('id');
|
|
491
|
+
|
|
438
492
|
if (nodeID) {
|
|
439
493
|
if (nodeIDs.has(nodeID)) {
|
|
440
494
|
continue;
|
|
441
495
|
}
|
|
496
|
+
|
|
442
497
|
nodeIDs.add(nodeID);
|
|
443
498
|
}
|
|
499
|
+
|
|
444
500
|
targetEdges.push(edge);
|
|
445
501
|
}
|
|
446
502
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -7,12 +7,9 @@
|
|
|
7
7
|
* strict-local
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
12
|
+
var _defineProperty2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/defineProperty"));
|
|
16
13
|
|
|
17
14
|
var CONNECTION_CALLS = {
|
|
18
15
|
after: true,
|
|
@@ -22,16 +19,15 @@ var CONNECTION_CALLS = {
|
|
|
22
19
|
last: true,
|
|
23
20
|
surrounds: true
|
|
24
21
|
};
|
|
25
|
-
|
|
26
22
|
var REQUIRED_RANGE_CALLS = {
|
|
27
23
|
find: true,
|
|
28
24
|
first: true,
|
|
29
25
|
last: true
|
|
30
26
|
};
|
|
31
|
-
|
|
32
27
|
var config = {
|
|
33
28
|
CLIENT_MUTATION_ID: 'clientMutationId',
|
|
34
29
|
CURSOR: 'cursor',
|
|
30
|
+
|
|
35
31
|
/**
|
|
36
32
|
* Whether `edges` fields are expected to have `source` fields.
|
|
37
33
|
*/
|
|
@@ -45,12 +41,12 @@ var config = {
|
|
|
45
41
|
PAGE_INFO: 'pageInfo',
|
|
46
42
|
START_CURSOR: 'startCursor'
|
|
47
43
|
};
|
|
48
|
-
|
|
49
44
|
/**
|
|
50
45
|
* @internal
|
|
51
46
|
*
|
|
52
47
|
* Defines logic relevant to the informal "Connection" GraphQL interface.
|
|
53
48
|
*/
|
|
49
|
+
|
|
54
50
|
var RelayConnectionInterface = {
|
|
55
51
|
inject: function inject(newConfig) {
|
|
56
52
|
config = newConfig;
|
|
@@ -59,7 +55,6 @@ var RelayConnectionInterface = {
|
|
|
59
55
|
return config;
|
|
60
56
|
},
|
|
61
57
|
|
|
62
|
-
|
|
63
58
|
/**
|
|
64
59
|
* Checks whether a call exists strictly to encode which parts of a connection
|
|
65
60
|
* to fetch. Fields that only differ by connection call values should have the
|
|
@@ -69,7 +64,6 @@ var RelayConnectionInterface = {
|
|
|
69
64
|
return CONNECTION_CALLS.hasOwnProperty(call.name);
|
|
70
65
|
},
|
|
71
66
|
|
|
72
|
-
|
|
73
67
|
/**
|
|
74
68
|
* Checks whether a set of calls on a connection supply enough information to
|
|
75
69
|
* fetch the range fields (i.e. `edges` and `page_info`).
|
|
@@ -80,15 +74,13 @@ var RelayConnectionInterface = {
|
|
|
80
74
|
});
|
|
81
75
|
},
|
|
82
76
|
|
|
83
|
-
|
|
84
77
|
/**
|
|
85
78
|
* Gets a default record representing a connection's `PAGE_INFO`.
|
|
86
79
|
*/
|
|
87
80
|
getDefaultPageInfo: function getDefaultPageInfo() {
|
|
88
81
|
var _ref;
|
|
89
82
|
|
|
90
|
-
return _ref = {}, (0,
|
|
83
|
+
return _ref = {}, (0, _defineProperty2["default"])(_ref, config.END_CURSOR, null), (0, _defineProperty2["default"])(_ref, config.HAS_NEXT_PAGE, false), (0, _defineProperty2["default"])(_ref, config.HAS_PREV_PAGE, false), (0, _defineProperty2["default"])(_ref, config.START_CURSOR, null), _ref;
|
|
91
84
|
}
|
|
92
85
|
};
|
|
93
|
-
|
|
94
86
|
module.exports = RelayConnectionInterface;
|
package/lib/RelayCore.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -7,30 +7,33 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
12
|
function createFragmentSpecResolver(context, containerName, fragments, props, callback) {
|
|
14
|
-
if (process.env.NODE_ENV !==
|
|
13
|
+
if (process.env.NODE_ENV !== "production") {
|
|
15
14
|
var fragmentNames = Object.keys(fragments);
|
|
16
15
|
fragmentNames.forEach(function (fragmentName) {
|
|
17
16
|
var propValue = props[fragmentName];
|
|
18
|
-
process.env.NODE_ENV !==
|
|
17
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(propValue !== undefined, 'createFragmentSpecResolver: Expected prop `%s` to be supplied to `%s`, but ' + 'got `undefined`. Pass an explicit `null` if this is intentional.', fragmentName, containerName) : void 0;
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
return new (require(
|
|
21
|
+
return new (require("./RelayModernFragmentSpecResolver"))(context, fragments, props, callback);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
module.exports = {
|
|
26
|
-
areEqualSelectors: require(
|
|
25
|
+
areEqualSelectors: require("./RelayModernSelector").areEqualSelectors,
|
|
27
26
|
createFragmentSpecResolver: createFragmentSpecResolver,
|
|
28
|
-
|
|
29
|
-
getDataIDsFromObject: require(
|
|
30
|
-
getFragment: require(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
createOperationDescriptor: require("./RelayModernOperationDescriptor").createOperationDescriptor,
|
|
28
|
+
getDataIDsFromObject: require("./RelayModernSelector").getDataIDsFromObject,
|
|
29
|
+
getFragment: require("./RelayModernGraphQLTag").getFragment,
|
|
30
|
+
getPaginationFragment: require("./RelayModernGraphQLTag").getPaginationFragment,
|
|
31
|
+
getRefetchableFragment: require("./RelayModernGraphQLTag").getRefetchableFragment,
|
|
32
|
+
getRequest: require("./RelayModernGraphQLTag").getRequest,
|
|
33
|
+
getSelector: require("./RelayModernSelector").getSelector,
|
|
34
|
+
getSelectorList: require("./RelayModernSelector").getSelectorList,
|
|
35
|
+
getSelectorsFromObject: require("./RelayModernSelector").getSelectorsFromObject,
|
|
36
|
+
getVariablesFromObject: require("./RelayModernSelector").getVariablesFromObject,
|
|
37
|
+
isFragment: require("./RelayModernGraphQLTag").isFragment,
|
|
38
|
+
isRequest: require("./RelayModernGraphQLTag").isRequest
|
|
36
39
|
};
|