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,188 +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
- * strict-local
8
- * @format
9
- */
10
- 'use strict';
11
-
12
- var _inheritsLoose2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/inheritsLoose"));
13
-
14
- /**
15
- * @internal
16
- *
17
- * Retrieves data for queries or fragments from disk into `cachedRecords`.
18
- */
19
- function restoreFragmentDataFromCache(dataID, fragment, path, store, cachedRecords, cachedRootCallMap, cacheManager, changeTracker, callbacks) {
20
- var restorator = new RelayCachedDataRestorator(cacheManager, store, cachedRecords, cachedRootCallMap, changeTracker, callbacks);
21
- restorator.restoreFragmentData(dataID, fragment, path);
22
- return {
23
- abort: function abort() {
24
- restorator.abort();
25
- }
26
- };
27
- }
28
-
29
- function restoreQueriesDataFromCache(queries, store, cachedRecords, cachedRootCallMap, cacheManager, changeTracker, callbacks) {
30
- var restorator = new RelayCachedDataRestorator(cacheManager, store, cachedRecords, cachedRootCallMap, changeTracker, callbacks);
31
- restorator.restoreQueriesData(queries);
32
- return {
33
- abort: function abort() {
34
- restorator.abort();
35
- }
36
- };
37
- }
38
-
39
- var RelayCachedDataRestorator =
40
- /*#__PURE__*/
41
- function (_RelayCacheProcessor) {
42
- (0, _inheritsLoose2["default"])(RelayCachedDataRestorator, _RelayCacheProcessor);
43
-
44
- function RelayCachedDataRestorator(cacheManager, store, cachedRecords, cachedRootCallMap, changeTracker, callbacks) {
45
- var _this;
46
-
47
- _this = _RelayCacheProcessor.call(this, cacheManager, callbacks) || this;
48
- _this._cachedRecords = cachedRecords;
49
- _this._cachedRootCallMap = cachedRootCallMap;
50
- _this._changeTracker = changeTracker;
51
- _this._store = store;
52
- return _this;
53
- }
54
-
55
- var _proto = RelayCachedDataRestorator.prototype;
56
-
57
- _proto.handleNodeVisited = function handleNodeVisited(node, dataID, record, nextState) {
58
- var recordState = this._store.getRecordState(dataID);
59
-
60
- this._cachedRecords[dataID] = record; // Mark records as created/updated as necessary. Note that if the
61
- // record is known to be deleted in the store then it will have been
62
- // been marked as created already. Further, it does not need to be
63
- // updated since no additional data can be read about a deleted node.
64
-
65
- if (recordState === 'UNKNOWN' && record !== undefined) {
66
- // Mark as created if the store did not have a record but disk cache
67
- // did (either a known record or known deletion).
68
- this._changeTracker.createID(dataID);
69
- } else if (recordState === 'EXISTENT' && record != null) {
70
- // Mark as updated only if a record exists in both the store and
71
- // disk cache.
72
- this._changeTracker.updateID(dataID);
73
- }
74
-
75
- if (!record) {
76
- // We are out of luck if disk doesn't have the node either.
77
- this.handleFailure();
78
- return;
79
- }
80
-
81
- if (require("./RelayRecord").isClientID(dataID)) {
82
- record.__path__ = nextState.path;
83
- }
84
- };
85
-
86
- _proto.handleIdentifiedRootVisited = function handleIdentifiedRootVisited(query, dataID, identifyingArgKey, nextState) {
87
- if (dataID == null) {
88
- // Read from cache and we still don't have a valid `dataID`.
89
- this.handleFailure();
90
- return;
91
- }
92
-
93
- var storageKey = query.getStorageKey();
94
- this._cachedRootCallMap[storageKey] = this._cachedRootCallMap[storageKey] || {};
95
- this._cachedRootCallMap[storageKey][identifyingArgKey || ''] = dataID;
96
- nextState.dataID = dataID;
97
- };
98
-
99
- _proto.restoreFragmentData = function restoreFragmentData(dataID, fragment, path) {
100
- var _this2 = this;
101
-
102
- this.process(function () {
103
- _this2.visitFragment(fragment, {
104
- dataID: dataID,
105
- node: fragment,
106
- path: path,
107
- rangeCalls: undefined
108
- });
109
- });
110
- };
111
-
112
- _proto.restoreQueriesData = function restoreQueriesData(queries) {
113
- var _this3 = this;
114
-
115
- this.process(function () {
116
- require("fbjs/lib/forEachObject")(queries, function (query) {
117
- if (_this3._state === 'COMPLETED') {
118
- return;
119
- }
120
-
121
- if (query) {
122
- _this3.visitRoot(query, {
123
- dataID: undefined,
124
- node: query,
125
- path: require("./RelayQueryPath").create(query),
126
- rangeCalls: undefined
127
- });
128
- }
129
- });
130
- });
131
- };
132
-
133
- _proto.traverse = function traverse(node, nextState) {
134
- !(nextState.dataID != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayCachedDataRestorator: Attempted to traverse without a ' + '`dataID`.') : require("fbjs/lib/invariant")(false) : void 0;
135
-
136
- var _findRelayQueryLeaves = require("./findRelayQueryLeaves")(this._store, this._cachedRecords, nextState.node, nextState.dataID, nextState.path, nextState.rangeCalls),
137
- missingData = _findRelayQueryLeaves.missingData,
138
- pendingNodeStates = _findRelayQueryLeaves.pendingNodeStates;
139
-
140
- if (missingData) {
141
- this.handleFailure();
142
- return;
143
- }
144
-
145
- for (var ii = 0; ii < pendingNodeStates.length; ii++) {
146
- if (this._state === 'COMPLETED') {
147
- return;
148
- }
149
-
150
- !(pendingNodeStates[ii].dataID != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayCachedDataRestorator: Attempted to visit a node without ' + 'a `dataID`.') : require("fbjs/lib/invariant")(false) : void 0;
151
- this.visitNode(pendingNodeStates[ii].node, pendingNodeStates[ii].dataID, pendingNodeStates[ii]);
152
- }
153
- };
154
-
155
- _proto.visitIdentifiedRoot = function visitIdentifiedRoot(query, identifyingArgKey, nextState) {
156
- var dataID = this._store.getDataID(query.getStorageKey(), identifyingArgKey);
157
-
158
- if (dataID == null) {
159
- _RelayCacheProcessor.prototype.visitIdentifiedRoot.call(this, query, identifyingArgKey, nextState);
160
- } else {
161
- this.traverse(query, {
162
- dataID: dataID,
163
- node: query,
164
- path: require("./RelayQueryPath").create(query),
165
- rangeCalls: undefined
166
- });
167
- }
168
- };
169
-
170
- return RelayCachedDataRestorator;
171
- }(require("./RelayCacheProcessor"));
172
-
173
- require("relay-runtime").RelayProfiler.instrumentMethods(RelayCachedDataRestorator.prototype, {
174
- handleIdentifiedRootVisited: 'RelayCachedDataRestorator.handleIdentifiedRootVisited',
175
- handleNodeVisited: 'RelayCachedDataRestorator.handleNodeVisited',
176
- queueIdentifiedRoot: 'RelayCachedDataRestorator.queueRoot',
177
- queueNode: 'RelayCachedDataRestorator.queueNode',
178
- restoreFragmentData: 'RelayCachedDataRestorator.readFragment',
179
- restoreQueriesData: 'RelayCachedDataRestorator.read',
180
- traverse: 'RelayCachedDataRestorator.traverse',
181
- visitNode: 'RelayCachedDataRestorator.visitNode',
182
- visitRoot: 'RelayCachedDataRestorator.visitRoot'
183
- });
184
-
185
- module.exports = {
186
- restoreFragmentDataFromCache: restoreFragmentDataFromCache,
187
- restoreQueriesDataFromCache: restoreQueriesDataFromCache
188
- };
@@ -1,42 +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
- /**
13
- * @internal
14
- *
15
- * Serializes a query "call" (a classic combination of field and argument value).
16
- */
17
- function serializeRelayQueryCall(call) {
18
- var value = call.value;
19
- var valueString;
20
-
21
- if (Array.isArray(value)) {
22
- valueString = require("fbjs/lib/flattenArray")(value).map(function (value) {
23
- return serializeCallValue(value);
24
- }).join(',');
25
- } else {
26
- valueString = serializeCallValue(value);
27
- }
28
-
29
- return '.' + call.name + '(' + valueString + ')';
30
- }
31
-
32
- function serializeCallValue(value) {
33
- if (value == null) {
34
- return '';
35
- } else if (typeof value !== 'string') {
36
- return JSON.stringify(value);
37
- } else {
38
- return value;
39
- }
40
- }
41
-
42
- module.exports = serializeRelayQueryCall;
@@ -1,298 +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 _inheritsLoose2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/inheritsLoose"));
13
-
14
- /**
15
- * Traverse `node` splitting off deferred query fragments into separate queries.
16
- *
17
- * @internal
18
- */
19
- function splitDeferredRelayQueries(node) {
20
- var splitter = new GraphQLSplitDeferredQueries();
21
- var splitQueries = {
22
- __nodePath__: [],
23
- __parent__: null,
24
- __refQuery__: null,
25
- deferred: [],
26
- required: null
27
- };
28
- splitter.visit(node, splitQueries);
29
- return buildQueries(splitQueries);
30
- }
31
- /**
32
- * Returns the requisite siblings of `node`, but filters any non-requisite
33
- * children of those siblings.
34
- */
35
-
36
-
37
- function getRequisiteSiblings(node, parent) {
38
- // Get the requisite siblings.
39
- var siblings = parent.getChildren().filter(function (child) {
40
- return child !== node && child instanceof require("./RelayQuery").Field && child.isRequisite();
41
- }); // Filter the non-requisite children from those siblings.
42
-
43
- return siblings.map(function (sibling) {
44
- var children = sibling.getChildren().filter(function (child) {
45
- return child instanceof require("./RelayQuery").Field && child.isRequisite();
46
- });
47
- var clone = sibling.clone(children);
48
- !clone ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'splitDeferredRelayQueries(): Unexpected non-scalar, requisite field.') : require("fbjs/lib/invariant")(false) : void 0;
49
- return clone;
50
- });
51
- }
52
- /**
53
- * Traverse the parent chain of `node` wrapping it at each level until it is
54
- * either:
55
- *
56
- * - wrapped in a RelayQuery.Root node
57
- * - wrapped in a non-root node that can be split off in a "ref query" (ie. a
58
- * root call with a ref param that references another query)
59
- *
60
- * Additionally ensures that any requisite sibling fields are embedded in each
61
- * layer of the wrapper.
62
- */
63
-
64
-
65
- function wrapNode(node, nodePath) {
66
- for (var ii = nodePath.length - 1; ii >= 0; ii--) {
67
- var parent = nodePath[ii];
68
-
69
- if (parent instanceof require("./RelayQuery").Field && parent.getInferredRootCallName()) {
70
- // We can make a "ref query" at this point, so stop wrapping.
71
- return new (require("./RelayRefQueryDescriptor"))(node, nodePath.slice(0, ii + 1));
72
- }
73
-
74
- var siblings = getRequisiteSiblings(node, parent);
75
- var children = [node].concat(siblings); // Cast here because we know that `clone` will never return `null` (because
76
- // we always give it at least one child).
77
-
78
- node = parent.clone(children);
79
- }
80
-
81
- !(node instanceof require("./RelayQuery").Root) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'splitDeferredRelayQueries(): Cannot build query without a root node.') : require("fbjs/lib/invariant")(false) : void 0;
82
- var identifyingArg = node.getIdentifyingArg();
83
- var identifyingArgName = identifyingArg && identifyingArg.name || null;
84
- var identifyingArgValue = identifyingArg && identifyingArg.value || null;
85
-
86
- var identifyingArgType = identifyingArg && identifyingArg.type || require("./RelayNodeInterface").ID_TYPE;
87
-
88
- var metadata = {
89
- identifyingArgName: identifyingArgName,
90
- identifyingArgType: identifyingArgType,
91
- isAbstract: true,
92
- isDeferred: true,
93
- isPlural: false
94
- };
95
- return require("./RelayQuery").Root.build(node.getName(), node.getFieldName(), identifyingArgValue, node.getChildren(), metadata, node.getType());
96
- }
97
- /**
98
- * Returns `true` if `node` is considered "empty", which means that it contains
99
- * no non-generated fields, and no ref query dependencies.
100
- */
101
-
102
-
103
- function isEmpty(node) {
104
- if (!node.canHaveSubselections()) {
105
- return node.isGenerated() && !node.isRefQueryDependency();
106
- } else {
107
- return node.getChildren().every(isEmpty);
108
- }
109
- }
110
- /**
111
- * Mutates and returns a nested `SplitQueries` structure, updating any deferred
112
- * "ref queries" to actually reference their contexts.
113
- */
114
-
115
-
116
- function buildQueries(splitQueries) {
117
- if (splitQueries.required && isEmpty(splitQueries.required)) {
118
- splitQueries.required = null;
119
- }
120
-
121
- splitQueries.deferred = splitQueries.deferred.map(function (nestedSplitQueries) {
122
- var descriptor = nestedSplitQueries.__refQuery__;
123
-
124
- if (descriptor) {
125
- // Wrap the ref query node with a reference to the required query that is
126
- // its context.
127
- var context = splitQueries.required;
128
-
129
- if (!context) {
130
- // Traverse upwards looking for context.
131
- var parentSplitQueries = splitQueries;
132
-
133
- while (parentSplitQueries.__parent__) {
134
- context = parentSplitQueries.__parent__.required;
135
-
136
- if (context) {
137
- break;
138
- }
139
-
140
- parentSplitQueries = parentSplitQueries.__parent__;
141
- }
142
- }
143
-
144
- !context ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'splitDeferredRelayQueries(): Expected a context root query.') : require("fbjs/lib/invariant")(false) : void 0;
145
- nestedSplitQueries.required = createRefQuery(descriptor, context);
146
- }
147
-
148
- return buildQueries(nestedSplitQueries);
149
- });
150
- return splitQueries;
151
- }
152
- /**
153
- * Wraps `descriptor` in a new top-level ref query.
154
- */
155
-
156
-
157
- function createRefQuery(descriptor, context) {
158
- var node = descriptor.node;
159
- !(node instanceof require("./RelayQuery").Field || node instanceof require("./RelayQuery").Fragment) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'splitDeferredRelayQueries(): Ref query requires a field or fragment.') : require("fbjs/lib/invariant")(false) : void 0; // Build up JSONPath.
160
-
161
- var jsonPath = ['$', '*'];
162
- var parent;
163
-
164
- for (var ii = 0; ii < descriptor.nodePath.length; ii++) {
165
- parent = descriptor.nodePath[ii];
166
-
167
- if (parent instanceof require("./RelayQuery").Field) {
168
- jsonPath.push(parent.getSerializationKey());
169
-
170
- if (parent.isPlural()) {
171
- jsonPath.push('*');
172
- }
173
- }
174
- }
175
-
176
- !(jsonPath.length > 2) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'splitDeferredRelayQueries(): Ref query requires a complete path.') : require("fbjs/lib/invariant")(false) : void 0;
177
- var field = parent; // Flow
178
-
179
- var primaryKey = field.getInferredPrimaryKey();
180
- !primaryKey ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'splitDeferredRelayQueries(): Ref query requires a primary key.') : require("fbjs/lib/invariant")(false) : void 0;
181
- jsonPath.push(primaryKey); // Create the wrapper root query.
182
-
183
- var root = require("./RelayQuery").Root.build(context.getName(), require("./RelayNodeInterface").NODES, require("./QueryBuilder").createBatchCallVariable(context.getID(), jsonPath.join('.')), [node], {
184
- identifyingArgName: require("./RelayNodeInterface").ID,
185
- identifyingArgType: require("./RelayNodeInterface").ID_TYPE,
186
- isAbstract: true,
187
- isDeferred: true,
188
- isPlural: false
189
- }, require("./RelayNodeInterface").NODE_TYPE);
190
-
191
- var result = root; // Flow
192
-
193
- return result;
194
- }
195
- /**
196
- * Traverses an input query, updating the passed in `SplitQueries` state object
197
- * to contain a nested structure representing the required and deferred portions
198
- * of the input query.
199
- */
200
-
201
-
202
- var GraphQLSplitDeferredQueries =
203
- /*#__PURE__*/
204
- function (_RelayQueryTransform) {
205
- (0, _inheritsLoose2["default"])(GraphQLSplitDeferredQueries, _RelayQueryTransform);
206
-
207
- function GraphQLSplitDeferredQueries() {
208
- return _RelayQueryTransform.apply(this, arguments) || this;
209
- }
210
-
211
- var _proto = GraphQLSplitDeferredQueries.prototype;
212
-
213
- _proto.visitField = function visitField(node, splitQueries) {
214
- if (!node.hasDeferredDescendant()) {
215
- return node;
216
- }
217
-
218
- splitQueries.__nodePath__.push(node);
219
-
220
- var result = this.traverse(node, splitQueries);
221
-
222
- splitQueries.__nodePath__.pop();
223
-
224
- if (result && node.getInferredRootCallName()) {
225
- // The node is a ref query dependency; mark it as one.
226
- var key = node.getInferredPrimaryKey();
227
- var children = result.getChildren().map(function (child) {
228
- if (child instanceof require("./RelayQuery").Field && child.getSchemaName() === key) {
229
- return child.cloneAsRefQueryDependency();
230
- } else {
231
- return child;
232
- }
233
- });
234
- result = result.clone(children);
235
- }
236
-
237
- return result;
238
- };
239
-
240
- _proto.visitFragment = function visitFragment(node, splitQueries) {
241
- if (!node.getChildren().length) {
242
- return null;
243
- }
244
-
245
- if (node.isDeferred()) {
246
- var nodePath = splitQueries.__nodePath__;
247
- var deferred = {
248
- __nodePath__: nodePath,
249
- __parent__: splitQueries,
250
- __refQuery__: null,
251
- deferred: [],
252
- required: null
253
- };
254
- var result = this.traverse(node, deferred);
255
-
256
- if (result) {
257
- var wrapped = wrapNode(result, nodePath);
258
-
259
- if (wrapped instanceof require("./RelayQuery").Root) {
260
- deferred.required = wrapped;
261
- } else if (wrapped instanceof require("./RelayRefQueryDescriptor")) {
262
- // for Flow
263
- deferred.__refQuery__ = wrapped;
264
- }
265
- }
266
-
267
- if (result || deferred.deferred.length) {
268
- splitQueries.deferred.push(deferred);
269
- }
270
-
271
- return null;
272
- } else if (node.hasDeferredDescendant()) {
273
- return this.traverse(node, splitQueries);
274
- } else {
275
- return node;
276
- }
277
- };
278
-
279
- _proto.visitRoot = function visitRoot(node, splitQueries) {
280
- if (!node.hasDeferredDescendant()) {
281
- splitQueries.required = node;
282
- return node;
283
- } else {
284
- splitQueries.__nodePath__.push(node);
285
-
286
- var result = this.traverse(node, splitQueries);
287
-
288
- splitQueries.__nodePath__.pop();
289
-
290
- splitQueries.required = result;
291
- return result;
292
- }
293
- };
294
-
295
- return GraphQLSplitDeferredQueries;
296
- }(require("./RelayQueryTransform"));
297
-
298
- module.exports = require("relay-runtime").RelayProfiler.instrument('splitDeferredRelayQueries', splitDeferredRelayQueries);
@@ -1,85 +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
- function isObject(value) {
13
- return value !== null && Object.prototype.toString.call(value) === '[object Object]';
14
- }
15
- /**
16
- * Simple recursive stringifier that handles basic objects (does not handle
17
- * corner cases such as circular references) and produces a JSON-like
18
- * serialization suitable for use as a cache key or other similar internal
19
- * book-keeping detail.
20
- *
21
- * Sample input:
22
- *
23
- * var object = {
24
- * top2: {
25
- * middle: {
26
- * inner: [1, 'foo', ['bar', 2]],
27
- * other: false,
28
- * },
29
- * },
30
- * top1: [
31
- * {first: true},
32
- * {first: false},
33
- * 'random',
34
- * ],
35
- * misc: true,
36
- * extra: null,
37
- * };
38
- *
39
- * Sample output (some whitespace added for clarity):
40
- *
41
- * {
42
- * extra:null,
43
- * misc:true,
44
- * top1:[0:{first:true},1:{first:false},2:"random"],
45
- * top2:{middle:{inner:[0:1,1:"foo",2:[0:"bar",1:2]],other:false}}
46
- * }
47
- */
48
-
49
-
50
- function stableStringify(input) {
51
- var inputIsArray = Array.isArray(input);
52
- var inputIsObject = isObject(input);
53
-
54
- if (inputIsArray || inputIsObject) {
55
- var keys = Object.keys(input);
56
-
57
- if (keys.length) {
58
- var result = [];
59
- keys.sort();
60
-
61
- for (var i = 0; i < keys.length; i++) {
62
- var key = keys[i];
63
- var value = input[key];
64
-
65
- if (isObject(value) || Array.isArray(value)) {
66
- value = stableStringify(value);
67
- } else {
68
- value = JSON.stringify(value);
69
- }
70
-
71
- result.push(key + ':' + value);
72
- }
73
-
74
- if (inputIsArray) {
75
- return '[' + result.join(',') + ']';
76
- } else {
77
- return '{' + result.join(',') + '}';
78
- }
79
- }
80
- }
81
-
82
- return JSON.stringify(input);
83
- }
84
-
85
- module.exports = stableStringify;