react-relay 2.0.0-rc.2 → 5.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.
Files changed (166) hide show
  1. package/index.js +2 -2
  2. package/lib/ReactRelayContext.js +6 -3
  3. package/lib/ReactRelayFragmentContainer.js +48 -46
  4. package/lib/ReactRelayFragmentMockRenderer.js +5 -1
  5. package/lib/ReactRelayPaginationContainer.js +102 -68
  6. package/lib/ReactRelayQueryFetcher.js +54 -28
  7. package/lib/ReactRelayQueryRenderer.js +28 -20
  8. package/lib/ReactRelayRefetchContainer.js +70 -58
  9. package/lib/ReactRelayTestMocker.js +56 -43
  10. package/lib/ReactRelayTypes.js +1 -1
  11. package/lib/RelayContext.js +8 -2
  12. package/lib/assertFragmentMap.js +9 -7
  13. package/lib/buildReactRelayContainer.js +32 -23
  14. package/lib/index.js +41 -0
  15. package/lib/isRelayEnvironment.js +1 -1
  16. package/lib/isRelayVariables.js +1 -1
  17. package/lib/readContext.js +7 -4
  18. package/package.json +4 -4
  19. package/react-relay.js +2 -2
  20. package/react-relay.min.js +2 -2
  21. package/classic.js +0 -10
  22. package/compat.js +0 -10
  23. package/lib/ConcreteQuery.js +0 -10
  24. package/lib/GraphQLQueryRunner.js +0 -264
  25. package/lib/GraphQLRange.js +0 -1124
  26. package/lib/GraphQLSegment.js +0 -743
  27. package/lib/GraphQLStoreChangeEmitter.js +0 -141
  28. package/lib/GraphQLStoreQueryResolver.js +0 -288
  29. package/lib/GraphQLStoreRangeUtils.js +0 -126
  30. package/lib/QueryBuilder.js +0 -228
  31. package/lib/ReactRelayClassicExports.js +0 -29
  32. package/lib/ReactRelayCompatContainerBuilder.js +0 -175
  33. package/lib/ReactRelayCompatPublic.js +0 -28
  34. package/lib/ReactRelayContainerProfiler.js +0 -30
  35. package/lib/ReactRelayFragmentContainer-flowtest.js +0 -201
  36. package/lib/ReactRelayPaginationContainer-flowtest.js +0 -213
  37. package/lib/ReactRelayPublic.js +0 -29
  38. package/lib/ReactRelayRefetchContainer-flowtest.js +0 -191
  39. package/lib/RelayCacheProcessor.js +0 -196
  40. package/lib/RelayChangeTracker.js +0 -83
  41. package/lib/RelayClassicContainerUtils.js +0 -49
  42. package/lib/RelayClassicCore.js +0 -34
  43. package/lib/RelayClassicRecordState.js +0 -31
  44. package/lib/RelayCompatContainer.js +0 -25
  45. package/lib/RelayCompatEnvironment.js +0 -27
  46. package/lib/RelayCompatMutations.js +0 -133
  47. package/lib/RelayCompatPaginationContainer.js +0 -27
  48. package/lib/RelayCompatRefetchContainer.js +0 -27
  49. package/lib/RelayCompatTypes.js +0 -10
  50. package/lib/RelayContainer.js +0 -889
  51. package/lib/RelayContainerComparators.js +0 -75
  52. package/lib/RelayContainerProxy.js +0 -21
  53. package/lib/RelayDefaultNetworkLayer.js +0 -192
  54. package/lib/RelayEnvironment.js +0 -449
  55. package/lib/RelayEnvironmentTypes.js +0 -10
  56. package/lib/RelayFetchMode.js +0 -17
  57. package/lib/RelayFragmentPointer.js +0 -161
  58. package/lib/RelayFragmentReference.js +0 -249
  59. package/lib/RelayFragmentSpecResolver.js +0 -305
  60. package/lib/RelayGraphQLMutation.js +0 -288
  61. package/lib/RelayGraphQLTag.js +0 -42
  62. package/lib/RelayInternalTypes.js +0 -15
  63. package/lib/RelayInternals.js +0 -24
  64. package/lib/RelayMetaRoute.js +0 -35
  65. package/lib/RelayMockRenderer.js +0 -71
  66. package/lib/RelayModern-flowtest.js +0 -342
  67. package/lib/RelayModernFlowtest_badref.graphql.js +0 -10
  68. package/lib/RelayModernFlowtest_notref.graphql.js +0 -10
  69. package/lib/RelayModernFlowtest_user.graphql.js +0 -10
  70. package/lib/RelayModernFlowtest_users.graphql.js +0 -10
  71. package/lib/RelayMutation.js +0 -322
  72. package/lib/RelayMutationDebugPrinter.js +0 -47
  73. package/lib/RelayMutationQuery.js +0 -558
  74. package/lib/RelayMutationQueue.js +0 -530
  75. package/lib/RelayMutationRequest.js +0 -103
  76. package/lib/RelayMutationTracker.js +0 -113
  77. package/lib/RelayMutationTransaction.js +0 -92
  78. package/lib/RelayMutationTransactionStatus.js +0 -55
  79. package/lib/RelayNetworkDebug.js +0 -131
  80. package/lib/RelayNetworkLayer.js +0 -185
  81. package/lib/RelayNodeInterface.js +0 -104
  82. package/lib/RelayOperationDescriptor.js +0 -40
  83. package/lib/RelayOptimisticMutationUtils.js +0 -208
  84. package/lib/RelayPendingQueryTracker.js +0 -166
  85. package/lib/RelayPropTypes.js +0 -57
  86. package/lib/RelayPublic.js +0 -44
  87. package/lib/RelayQL.js +0 -128
  88. package/lib/RelayQuery.js +0 -1584
  89. package/lib/RelayQueryCaching.js +0 -33
  90. package/lib/RelayQueryConfig.js +0 -58
  91. package/lib/RelayQueryPath.js +0 -204
  92. package/lib/RelayQueryRequest.js +0 -103
  93. package/lib/RelayQueryTracker.js +0 -86
  94. package/lib/RelayQueryTransform.js +0 -91
  95. package/lib/RelayQueryVisitor.js +0 -93
  96. package/lib/RelayQueryWriter.js +0 -573
  97. package/lib/RelayReadyState.js +0 -83
  98. package/lib/RelayReadyStateRenderer.js +0 -145
  99. package/lib/RelayRecord.js +0 -75
  100. package/lib/RelayRecordStatusMap.js +0 -57
  101. package/lib/RelayRecordStore.js +0 -433
  102. package/lib/RelayRecordWriter.js +0 -601
  103. package/lib/RelayRefQueryDescriptor.js +0 -27
  104. package/lib/RelayRenderer.js +0 -268
  105. package/lib/RelayRootContainer.js +0 -125
  106. package/lib/RelayRoute.js +0 -92
  107. package/lib/RelayRouteFragment.js +0 -44
  108. package/lib/RelaySelector.js +0 -201
  109. package/lib/RelayShallowMock.js +0 -69
  110. package/lib/RelayStaticContainer.js +0 -38
  111. package/lib/RelayStore.js +0 -12
  112. package/lib/RelayStoreConstants.js +0 -20
  113. package/lib/RelayStoreData.js +0 -660
  114. package/lib/RelayTaskQueue.js +0 -189
  115. package/lib/RelayTypes.js +0 -13
  116. package/lib/RelayVariable.js +0 -32
  117. package/lib/RelayVariables.js +0 -92
  118. package/lib/buildRQL.js +0 -160
  119. package/lib/callsFromGraphQL.js +0 -74
  120. package/lib/callsToGraphQL.js +0 -34
  121. package/lib/checkRelayQueryData.js +0 -250
  122. package/lib/createRelayQuery.js +0 -17
  123. package/lib/dedent.js +0 -49
  124. package/lib/diffRelayQuery.js +0 -757
  125. package/lib/directivesToGraphQL.js +0 -39
  126. package/lib/filterRelayQuery.js +0 -29
  127. package/lib/findRelayQueryLeaves.js +0 -293
  128. package/lib/flattenRelayQuery.js +0 -121
  129. package/lib/flattenSplitRelayQueries.js +0 -44
  130. package/lib/forEachRootCallArg.js +0 -40
  131. package/lib/fromGraphQL.js +0 -48
  132. package/lib/generateClientEdgeID.js +0 -22
  133. package/lib/generateClientID.js +0 -27
  134. package/lib/generateConcreteFragmentID.js +0 -30
  135. package/lib/generateForceIndex.js +0 -24
  136. package/lib/generateRQLFieldAlias.js +0 -39
  137. package/lib/getRangeBehavior.js +0 -58
  138. package/lib/getRelayQueries.js +0 -83
  139. package/lib/intersectRelayQuery.js +0 -149
  140. package/lib/isClassicRelayContext.js +0 -20
  141. package/lib/isClassicRelayEnvironment.js +0 -20
  142. package/lib/isCompatibleRelayFragmentType.js +0 -27
  143. package/lib/isRelayContainer.js +0 -16
  144. package/lib/makeLegacyStringishComponentRef.js +0 -52
  145. package/lib/printRelayOSSQuery.js +0 -329
  146. package/lib/printRelayQuery.js +0 -26
  147. package/lib/rangeOperationToMetadataKey.js +0 -25
  148. package/lib/readRelayQueryData.js +0 -551
  149. package/lib/relayUnstableBatchedUpdates.js +0 -12
  150. package/lib/relayUnstableBatchedUpdates.native.js +0 -11
  151. package/lib/restoreRelayCacheData.js +0 -188
  152. package/lib/serializeRelayQueryCall.js +0 -42
  153. package/lib/splitDeferredRelayQueries.js +0 -298
  154. package/lib/stableStringify.js +0 -85
  155. package/lib/testEditDistance.js +0 -112
  156. package/lib/throwFailedPromise.js +0 -26
  157. package/lib/toGraphQL.js +0 -94
  158. package/lib/transformRelayQueryPayload.js +0 -145
  159. package/lib/validateMutationConfig.js +0 -117
  160. package/lib/validateRelayReadQuery.js +0 -112
  161. package/lib/writeRelayQueryPayload.js +0 -44
  162. package/lib/writeRelayUpdatePayload.js +0 -513
  163. package/react-relay-classic.js +0 -4
  164. package/react-relay-classic.min.js +0 -9
  165. package/react-relay-compat.js +0 -4
  166. package/react-relay-compat.min.js +0 -9
@@ -1,513 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
- 'use strict';
11
-
12
- var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
13
-
14
- var APPEND = require("relay-runtime").RangeOperations.APPEND,
15
- IGNORE = require("relay-runtime").RangeOperations.IGNORE,
16
- PREPEND = require("relay-runtime").RangeOperations.PREPEND,
17
- REFETCH = require("relay-runtime").RangeOperations.REFETCH,
18
- REMOVE = require("relay-runtime").RangeOperations.REMOVE;
19
-
20
- var _edgesField;
21
-
22
- function getEdgesField() {
23
- if (!_edgesField) {
24
- _edgesField = require("./RelayQuery").Field.build({
25
- fieldName: require("relay-runtime").ConnectionInterface.get().EDGES,
26
- type: require("./RelayNodeInterface").ANY_TYPE,
27
- metadata: {
28
- canHaveSubselections: true,
29
- isPlural: true
30
- }
31
- });
32
- }
33
-
34
- return _edgesField;
35
- }
36
-
37
- var STUB_CURSOR_ID = 'client:cursor';
38
- /**
39
- * @internal
40
- *
41
- * Applies the results of an update operation (mutation/subscription) to the
42
- * store.
43
- */
44
-
45
- function writeRelayUpdatePayload(writer, operation, payload, _ref) {
46
- var configs = _ref.configs,
47
- isOptimisticUpdate = _ref.isOptimisticUpdate;
48
- configs.forEach(function (config) {
49
- switch (config.type) {
50
- case require("relay-runtime").MutationTypes.NODE_DELETE:
51
- handleNodeDelete(writer, payload, config);
52
- break;
53
-
54
- case require("relay-runtime").MutationTypes.RANGE_ADD:
55
- handleRangeAdd(writer, payload, operation, config, isOptimisticUpdate);
56
- break;
57
-
58
- case require("relay-runtime").MutationTypes.RANGE_DELETE:
59
- handleRangeDelete(writer, payload, config);
60
- break;
61
-
62
- case require("relay-runtime").MutationTypes.FIELDS_CHANGE:
63
- case require("relay-runtime").MutationTypes.REQUIRED_CHILDREN:
64
- break;
65
-
66
- default:
67
- console.error('Expected a valid mutation handler type, got `%s`.', config.type);
68
- }
69
- });
70
- handleMerge(writer, payload, operation);
71
- }
72
- /**
73
- * Handles the payload for a node deletion mutation, reading the ID of the node
74
- * to delete from the payload based on the config and then deleting references
75
- * to the node.
76
- */
77
-
78
-
79
- function handleNodeDelete(writer, payload, config) {
80
- var recordIDs = payload[config.deletedIDFieldName];
81
-
82
- if (!recordIDs) {
83
- // for some mutations, deletions don't always occur so if there's no field
84
- // in the payload, carry on
85
- return;
86
- }
87
-
88
- if (Array.isArray(recordIDs)) {
89
- recordIDs.forEach(function (id) {
90
- /* $FlowFixMe(>=0.36.0) Flow error detected during
91
- * the deploy of Flow v0.36.0. To see the error, remove this comment and
92
- * run Flow */
93
- deleteRecord(writer, id);
94
- });
95
- } else {
96
- // $FlowFixMe(>=0.33.0)
97
- deleteRecord(writer, recordIDs);
98
- }
99
- }
100
- /**
101
- * Deletes the record from the store, also removing any references to the node
102
- * from any ranges that contain it (along with the containing edges).
103
- */
104
-
105
-
106
- function deleteRecord(writer, recordID) {
107
- var store = writer.getRecordStore();
108
- var recordWriter = writer.getRecordWriter(); // skip if already deleted
109
-
110
- var status = store.getRecordState(recordID);
111
-
112
- if (status === require("./RelayClassicRecordState").NONEXISTENT) {
113
- return;
114
- } // Delete the node from any ranges it may be a part of
115
-
116
-
117
- var connectionIDs = store.getConnectionIDsForRecord(recordID);
118
-
119
- if (connectionIDs) {
120
- connectionIDs.forEach(function (connectionID) {
121
- var edgeID = require("./generateClientEdgeID")(connectionID, recordID);
122
-
123
- recordWriter.applyRangeUpdate(connectionID, edgeID, REMOVE);
124
- writer.recordUpdate(edgeID);
125
- writer.recordUpdate(connectionID); // edges are never nodes, so this will not infinitely recurse
126
-
127
- deleteRecord(writer, edgeID);
128
- });
129
- } // delete the node
130
-
131
-
132
- recordWriter.deleteRecord(recordID);
133
- writer.recordUpdate(recordID);
134
- }
135
- /**
136
- * Handles merging the results of the mutation/subscription into the store,
137
- * updating each top-level field in the data according the fetched
138
- * fields/fragments.
139
- */
140
-
141
-
142
- function handleMerge(writer, payload, operation) {
143
- var store = writer.getRecordStore(); // because optimistic payloads may not contain all fields, we loop over
144
- // the data that is present and then have to recurse the query to find
145
- // the matching fields.
146
- //
147
- // TODO #7167718: more efficient mutation/subscription writes
148
-
149
- for (var fieldName in payload) {
150
- if (!Object.prototype.hasOwnProperty.call(payload, fieldName)) {
151
- continue;
152
- }
153
-
154
- var payloadData = payload[fieldName]; // #9357395
155
-
156
- if (typeof payloadData !== 'object' || payloadData == null) {
157
- continue;
158
- } // check for valid data (has an ID or is an array) and write the field
159
-
160
-
161
- if (require("./RelayNodeInterface").ID in payloadData || // if the field is an argument-less root call, determine the corresponding
162
- // root record ID
163
- store.getDataID(fieldName) || Array.isArray(payloadData)) {
164
- mergeField(writer, fieldName, payloadData, operation);
165
- }
166
- }
167
- }
168
- /**
169
- * Merges the results of a single top-level field into the store.
170
- */
171
-
172
-
173
- function mergeField(writer, fieldName, payload, operation) {
174
- // don't write mutation/subscription metadata fields
175
- var _ConnectionInterface$ = require("relay-runtime").ConnectionInterface.get(),
176
- CLIENT_MUTATION_ID = _ConnectionInterface$.CLIENT_MUTATION_ID;
177
-
178
- if (fieldName === 'error' || fieldName === CLIENT_MUTATION_ID) {
179
- return;
180
- }
181
-
182
- if (Array.isArray(payload)) {
183
- payload.forEach(function (item) {
184
- if (typeof item === 'object' && item != null && !Array.isArray(item)) {
185
- if (getString(item, require("./RelayNodeInterface").ID)) {
186
- mergeField(writer, fieldName, item, operation);
187
- }
188
- }
189
- });
190
- return;
191
- } // reassign to preserve type information in below closure
192
-
193
-
194
- var payloadData = payload;
195
- var store = writer.getRecordStore();
196
- var recordID = getString(payloadData, require("./RelayNodeInterface").ID);
197
- var path;
198
-
199
- if (recordID != null) {
200
- path = require("./RelayQueryPath").createForID(recordID, 'writeRelayUpdatePayload');
201
- } else {
202
- recordID = store.getDataID(fieldName);
203
-
204
- if (!recordID) {
205
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Expected a record ID in the response ' + 'payload supplied to update the store for field `%s`, ' + 'payload keys [%s], operation name `%s`.', fieldName, Object.keys(payload).join(', '), operation.getName()) : require("fbjs/lib/invariant")(false) : void 0;
206
- } // Root fields that do not accept arguments
207
-
208
-
209
- path = require("./RelayQueryPath").create(require("./RelayQuery").Root.build('writeRelayUpdatePayload', fieldName, null, null, {
210
- identifyingArgName: null,
211
- identifyingArgType: null,
212
- isAbstract: true,
213
- isDeferred: false,
214
- isPlural: false
215
- }, require("./RelayNodeInterface").ANY_TYPE));
216
- } // write the results for only the current field, for every instance of that
217
- // field in any subfield/fragment in the query.
218
-
219
-
220
- var handleNode = function handleNode(node) {
221
- node.getChildren().forEach(function (child) {
222
- if (child instanceof require("./RelayQuery").Fragment) {
223
- handleNode(child);
224
- } else if (child instanceof require("./RelayQuery").Field && child.getSerializationKey() === fieldName) {
225
- // for flow: types are lost in closures
226
- if (path && recordID) {
227
- // ensure the record exists and then update it
228
- writer.createRecordIfMissing(child, recordID, path, payloadData);
229
- writer.writePayload(child, recordID, payloadData, path);
230
- }
231
- }
232
- });
233
- };
234
-
235
- handleNode(operation);
236
- }
237
- /**
238
- * Handles the payload for a range addition. The configuration specifies:
239
- * - which field in the payload contains data for the new edge
240
- * - the list of fetched ranges to which the edge should be added
241
- * - whether to append/prepend to each of those ranges
242
- */
243
-
244
-
245
- function handleRangeAdd(writer, payload, operation, config, isOptimisticUpdate) {
246
- var _ConnectionInterface$2 = require("relay-runtime").ConnectionInterface.get(),
247
- CLIENT_MUTATION_ID = _ConnectionInterface$2.CLIENT_MUTATION_ID;
248
-
249
- var clientMutationID = getString(payload, CLIENT_MUTATION_ID);
250
- !clientMutationID ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Expected operation `%s` to have a `%s`.', operation.getName(), CLIENT_MUTATION_ID) : require("fbjs/lib/invariant")(false) : void 0;
251
- var store = writer.getRecordStore(); // Extracts the new edge from the payload
252
-
253
- var edge = getObject(payload, config.edgeName);
254
- var edgeNode = edge && getObject(edge, require("./RelayNodeInterface").NODE);
255
-
256
- if (!edge || !edgeNode) {
257
- return;
258
- } // Extract the id of the node with the connection that we are adding to.
259
-
260
-
261
- var connectionParentID = config.parentID;
262
-
263
- if (!connectionParentID) {
264
- var edgeSource = getObject(edge, 'source');
265
-
266
- if (edgeSource) {
267
- connectionParentID = getString(edgeSource, require("./RelayNodeInterface").ID);
268
- }
269
- }
270
-
271
- !connectionParentID ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Cannot insert edge without a configured ' + '`parentID` or a `%s.source.id` field.', config.edgeName) : require("fbjs/lib/invariant")(false) : void 0;
272
-
273
- var nodeID = getString(edgeNode, require("./RelayNodeInterface").ID) || require("./generateClientID")();
274
-
275
- var cursor = edge.cursor || STUB_CURSOR_ID;
276
- var edgeData = (0, _objectSpread2["default"])({}, edge, {
277
- cursor: cursor,
278
- node: (0, _objectSpread2["default"])({}, edgeNode, {
279
- id: nodeID
280
- })
281
- }); // add the node to every connection for this field
282
-
283
- var connectionIDs = store.getConnectionIDsForField(connectionParentID, config.connectionName);
284
-
285
- if (connectionIDs) {
286
- connectionIDs.forEach(function (connectionID) {
287
- return addRangeNode(writer, operation, config, connectionID, nodeID, edgeData);
288
- });
289
- }
290
-
291
- if (isOptimisticUpdate) {
292
- // optimistic updates need to record the generated client ID for
293
- // a to-be-created node
294
- require("./RelayMutationTracker").putClientIDForMutation(nodeID, clientMutationID);
295
- } else {
296
- // non-optimistic updates check for the existence of a generated client
297
- // ID (from the above `if` clause) and link the client ID to the actual
298
- // server ID.
299
- var clientNodeID = require("./RelayMutationTracker").getClientIDForMutation(clientMutationID);
300
-
301
- if (clientNodeID) {
302
- require("./RelayMutationTracker").updateClientServerIDMap(clientNodeID, nodeID);
303
-
304
- require("./RelayMutationTracker").deleteClientIDForMutation(clientMutationID);
305
- }
306
- }
307
- }
308
- /**
309
- * Writes the node data for the given field to the store and prepends/appends
310
- * the node to the given connection.
311
- */
312
-
313
-
314
- function addRangeNode(writer, operation, config, connectionID, nodeID, edgeData) {
315
- var store = writer.getRecordStore();
316
- var recordWriter = writer.getRecordWriter();
317
- var filterCalls = store.getRangeFilterCalls(connectionID);
318
- var rangeBehavior = filterCalls ? require("./getRangeBehavior")(config.rangeBehaviors, filterCalls) : null; // no range behavior specified for this combination of filter calls
319
-
320
- if (!rangeBehavior) {
321
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(rangeBehavior, 'Using `null` as a rangeBehavior value is deprecated. Use `ignore` to avoid ' + 'refetching a range.') : void 0;
322
- return;
323
- }
324
-
325
- if (rangeBehavior === IGNORE) {
326
- return;
327
- }
328
-
329
- var edgeID = require("./generateClientEdgeID")(connectionID, nodeID);
330
-
331
- var path = store.getPathToRecord(connectionID);
332
- !path ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Expected a path for connection record, `%s`.', connectionID) : require("fbjs/lib/invariant")(false) : void 0;
333
- var edgesField = getEdgesField();
334
- path = require("./RelayQueryPath").getPath(path, edgesField, edgeID); // create the edge record
335
-
336
- writer.createRecordIfMissing(edgesField, edgeID, path, edgeData); // write data for all `edges` fields
337
- // TODO #7167718: more efficient mutation/subscription writes
338
-
339
- var hasEdgeField = false;
340
-
341
- var handleNode = function handleNode(node) {
342
- node.getChildren().forEach(function (child) {
343
- if (child instanceof require("./RelayQuery").Fragment) {
344
- handleNode(child);
345
- } else if (child instanceof require("./RelayQuery").Field && child.getSchemaName() === config.edgeName) {
346
- hasEdgeField = true;
347
-
348
- if (path) {
349
- writer.writePayload(child, edgeID, edgeData, path);
350
- }
351
- }
352
- });
353
- };
354
-
355
- handleNode(operation);
356
- !hasEdgeField ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Expected mutation query to include the ' + 'relevant edge field, `%s`.', config.edgeName) : require("fbjs/lib/invariant")(false) : void 0; // append/prepend the item to the range.
357
-
358
- if (rangeBehavior === APPEND || rangeBehavior === IGNORE || rangeBehavior === PREPEND || rangeBehavior === REFETCH || rangeBehavior === REMOVE) {
359
- recordWriter.applyRangeUpdate(connectionID, edgeID, rangeBehavior);
360
- writer.recordUpdate(connectionID);
361
- } else {
362
- console.error('writeRelayUpdatePayload(): invalid range operation `%s`, valid ' + 'options are `%s`, `%s`, `%s`, `%s`, or `%s`.', rangeBehavior, APPEND, PREPEND, IGNORE, REMOVE, REFETCH);
363
- }
364
- }
365
- /**
366
- * Handles the payload for a range edge deletion, which removes the edge from
367
- * a specified range but does not delete the node for that edge. The config
368
- * specifies the path within the payload that contains the connection ID.
369
- */
370
-
371
-
372
- function handleRangeDelete(writer, payload, config) {
373
- var store = writer.getRecordStore();
374
- var recordIDs = null;
375
-
376
- if (Array.isArray(config.deletedIDFieldName)) {
377
- recordIDs = getIDsFromPath(store, config.deletedIDFieldName, payload);
378
- } else {
379
- recordIDs = payload[config.deletedIDFieldName]; // Coerce numbers to strings for backwards compatibility.
380
-
381
- if (typeof recordIDs === 'number') {
382
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'writeRelayUpdatePayload(): Expected `%s` to be a string, got the ' + 'number `%s`.', config.deletedIDFieldName, recordIDs) : void 0;
383
- recordIDs = '' + recordIDs;
384
- }
385
-
386
- !(recordIDs == null || !Array.isArray(recordIDs) || typeof recordIDs !== 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Expected `%s` to be an array/string, got `%s`.', config.deletedIDFieldName, JSON.stringify(recordIDs)) : require("fbjs/lib/invariant")(false) : void 0;
387
-
388
- if (!Array.isArray(recordIDs)) {
389
- recordIDs = [recordIDs];
390
- }
391
- }
392
-
393
- !(recordIDs != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Missing ID(s) for deleted record at field `%s`.', config.deletedIDFieldName) : require("fbjs/lib/invariant")(false) : void 0; // Extract the id of the node with the connection that we are deleting from.
394
-
395
- var connectionName = config.pathToConnection.pop();
396
- var connectionParentIDs = getIDsFromPath(store, config.pathToConnection, payload); // Restore pathToConnection to its original state
397
-
398
- config.pathToConnection.push(connectionName);
399
-
400
- if (!connectionParentIDs) {
401
- return;
402
- }
403
-
404
- var connectionParentID = connectionParentIDs[0];
405
- var connectionIDs = store.getConnectionIDsForField(connectionParentID, connectionName);
406
-
407
- if (connectionIDs) {
408
- connectionIDs.forEach(function (connectionID) {
409
- if (recordIDs) {
410
- recordIDs.forEach(function (recordID) {
411
- deleteRangeEdge(writer, connectionID, recordID);
412
- });
413
- }
414
- });
415
- }
416
- }
417
- /**
418
- * Removes an edge from a connection without modifying the node data.
419
- */
420
-
421
-
422
- function deleteRangeEdge(writer, connectionID, nodeID) {
423
- var recordWriter = writer.getRecordWriter();
424
-
425
- var edgeID = require("./generateClientEdgeID")(connectionID, nodeID);
426
-
427
- recordWriter.applyRangeUpdate(connectionID, edgeID, REMOVE);
428
- deleteRecord(writer, edgeID);
429
- writer.recordUpdate(connectionID);
430
- }
431
- /**
432
- * Given a payload of data and a path of fields, extracts the `id` of the node(s)
433
- * specified by the path.
434
- *
435
- * Examples:
436
- * path: ['root', 'field']
437
- * data: {root: {field: {id: 'xyz'}}}
438
- *
439
- * path: ['root', 'field']
440
- * data: {root: {field: [{id: 'abc'}, {id: 'def'}]}}
441
- *
442
- * Returns:
443
- * ['xyz']
444
- *
445
- * ['abc', 'def']
446
- */
447
-
448
-
449
- function getIDsFromPath(store, path, payload) {
450
- // We have a special case for the path for root nodes without ids like
451
- // ['viewer']. We try to match it up with something in the root call mapping
452
- // first.
453
- if (path.length === 1) {
454
- var rootCallID = store.getDataID(path[0]);
455
-
456
- if (rootCallID) {
457
- return [rootCallID];
458
- }
459
- }
460
-
461
- var payloadItems = payload;
462
- path.forEach(function (step, idx) {
463
- if (!payloadItems || Array.isArray(payloadItems)) {
464
- return;
465
- }
466
-
467
- if (idx === path.length - 1) {
468
- payloadItems = getObjectOrArray(payloadItems, step);
469
- } else {
470
- payloadItems = getObject(payloadItems, step);
471
- }
472
- });
473
-
474
- if (payloadItems) {
475
- if (!Array.isArray(payloadItems)) {
476
- payloadItems = [payloadItems];
477
- }
478
-
479
- return payloadItems.map(function (item) {
480
- var id = getString(item, require("./RelayNodeInterface").ID);
481
- !(id != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Expected `%s.id` to be a string.', path.join('.')) : require("fbjs/lib/invariant")(false) : void 0;
482
- return id;
483
- });
484
- }
485
-
486
- return null;
487
- }
488
-
489
- function getString(payload, field) {
490
- var value = payload[field]; // Coerce numbers to strings for backwards compatibility.
491
-
492
- if (typeof value === 'number') {
493
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'writeRelayUpdatePayload(): Expected `%s` to be a string, got the ' + 'number `%s`.', field, value) : void 0;
494
- value = '' + value;
495
- }
496
-
497
- !(value == null || typeof value === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Expected `%s` to be a string, got `%s`.', field, JSON.stringify(value)) : require("fbjs/lib/invariant")(false) : void 0;
498
- return value;
499
- }
500
-
501
- function getObject(payload, field) {
502
- var value = payload[field];
503
- !(value == null || typeof value === 'object' && !Array.isArray(value)) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Expected `%s` to be an object, got `%s`.', field, JSON.stringify(value)) : require("fbjs/lib/invariant")(false) : void 0;
504
- return value;
505
- }
506
-
507
- function getObjectOrArray(payload, field) {
508
- var value = payload[field];
509
- !(value == null || typeof value === 'object') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeRelayUpdatePayload(): Expected `%s` to be an object/array, got `%s`.', field, JSON.stringify(value)) : require("fbjs/lib/invariant")(false) : void 0;
510
- return value;
511
- }
512
-
513
- module.exports = require("relay-runtime").RelayProfiler.instrument('writeRelayUpdatePayload', writeRelayUpdatePayload);