react-relay 2.0.0-rc.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,33 +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
8
- * @format
9
- */
10
- 'use strict';
11
-
12
- var queryCachingEnabled = true;
13
- /**
14
- * Methods for configuring caching of Relay queries.
15
- */
16
-
17
- var RelayQueryCaching = {
18
- /**
19
- * `disable` turns off caching of queries for `getRelayQueries` and
20
- * `buildRQL`.
21
- */
22
- disable: function disable() {
23
- queryCachingEnabled = false;
24
- },
25
-
26
- /**
27
- * @internal
28
- */
29
- getEnabled: function getEnabled() {
30
- return queryCachingEnabled;
31
- }
32
- };
33
- module.exports = RelayQueryCaching;
@@ -1,58 +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
- /**
15
- * Configures the root queries and initial variables that define the context in
16
- * which the top-level component's fragments are requested. This is meant to be
17
- * subclassed, of which instances are supplied to `RelayRootContainer`.
18
- */
19
- var RelayQueryConfig =
20
- /*#__PURE__*/
21
- function () {
22
- // TODO: Deprecate `routeName`, #8478719.
23
- function RelayQueryConfig(initialVariables) {
24
- !(this.constructor !== RelayQueryConfig) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryConfig: Abstract class cannot be instantiated.') : require("fbjs/lib/invariant")(false) : void 0;
25
- Object.defineProperty(this, 'name', {
26
- enumerable: true,
27
- value: this.constructor.routeName
28
- });
29
- Object.defineProperty(this, 'params', {
30
- enumerable: true,
31
- value: this.prepareVariables((0, _objectSpread2["default"])({}, initialVariables)) || {}
32
- });
33
- Object.defineProperty(this, 'queries', {
34
- enumerable: true,
35
- value: (0, _objectSpread2["default"])({}, this.constructor.queries)
36
- });
37
-
38
- if (process.env.NODE_ENV !== "production") {
39
- Object.freeze(this.params);
40
- Object.freeze(this.queries);
41
- }
42
- }
43
- /**
44
- * Provides an opportunity to perform additional logic on the variables.
45
- * Child class should override this function to perform custom logic.
46
- */
47
-
48
-
49
- var _proto = RelayQueryConfig.prototype;
50
-
51
- _proto.prepareVariables = function prepareVariables(prevVariables) {
52
- return prevVariables;
53
- };
54
-
55
- return RelayQueryConfig;
56
- }();
57
-
58
- module.exports = RelayQueryConfig;
@@ -1,204 +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 idField = require("./RelayQuery").Field.build({
13
- fieldName: require("./RelayNodeInterface").ID,
14
- type: 'String'
15
- });
16
-
17
- var typeField = require("./RelayQuery").Field.build({
18
- fieldName: require("./RelayNodeInterface").TYPENAME,
19
- type: 'String'
20
- });
21
-
22
- // Placeholder path used to write data to root record (ROOT_ID).
23
- var ROOT_RECORD_PATH = {
24
- type: 'rootRecord'
25
- };
26
-
27
- /**
28
- * @internal
29
- *
30
- * Represents the path (root plus fields) within a query that fetched a
31
- * particular node. Each step of the path may represent a root query (for
32
- * refetchable nodes) or the field path from the nearest refetchable node.
33
- */
34
- var RelayQueryPath = {
35
- getRootRecordPath: function getRootRecordPath() {
36
- return ROOT_RECORD_PATH;
37
- },
38
- createForID: function createForID(dataID, name, routeName) {
39
- !!require("./RelayRecord").isClientID(dataID) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryPath.createForID: Expected dataID to be a server id, got ' + '`%s`.', dataID) : require("fbjs/lib/invariant")(false) : void 0;
40
- return {
41
- dataID: dataID,
42
- name: name,
43
- routeName: routeName || '$RelayQuery',
44
- type: 'node'
45
- };
46
- },
47
- create: function create(root) {
48
- if (root.getFieldName() === require("./RelayNodeInterface").NODE) {
49
- var identifyingArg = root.getIdentifyingArg();
50
-
51
- if (identifyingArg && typeof identifyingArg.value === 'string') {
52
- return {
53
- dataID: identifyingArg.value,
54
- name: root.getName(),
55
- routeName: root.getRoute().name,
56
- type: 'node'
57
- };
58
- }
59
- }
60
-
61
- return {
62
- root: root,
63
- type: 'root'
64
- };
65
- },
66
- getPath: function getPath(parent, node, dataID) {
67
- if (dataID == null || require("./RelayRecord").isClientID(dataID)) {
68
- return {
69
- node: node,
70
- parent: parent,
71
- type: 'client'
72
- };
73
- } else if (parent.type === 'node' && parent.dataID === dataID) {
74
- return parent;
75
- } else {
76
- return {
77
- dataID: dataID,
78
- name: RelayQueryPath.getName(parent),
79
- routeName: RelayQueryPath.getRouteName(parent),
80
- type: 'node'
81
- };
82
- }
83
- },
84
- isRootPath: function isRootPath(path) {
85
- return path.type === 'node' || path.type === 'root';
86
- },
87
- getParent: function getParent(path) {
88
- !(path.type === 'client') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryPath: Cannot get the parent of a root path.') : require("fbjs/lib/invariant")(false) : void 0;
89
- return path.parent;
90
- },
91
- getName: function getName(path) {
92
- while (path.type === 'client') {
93
- path = path.parent;
94
- }
95
-
96
- if (path === ROOT_RECORD_PATH) {
97
- return 'RootRecordPath';
98
- } else if (path.type === 'root') {
99
- return path.root.getName();
100
- } else if (path.type === 'node') {
101
- return path.name;
102
- } else {
103
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryPath.getName(): Invalid path `%s`.', path) : require("fbjs/lib/invariant")(false) : void 0;
104
- }
105
- },
106
- getRouteName: function getRouteName(path) {
107
- while (path.type === 'client') {
108
- path = path.parent;
109
- }
110
-
111
- if (path === ROOT_RECORD_PATH) {
112
- return '$RelayQueryPath';
113
- } else if (path.type === 'root') {
114
- return path.root.getRoute().name;
115
- } else if (path.type === 'node') {
116
- return path.routeName;
117
- } else {
118
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryPath.getRouteName(): Invalid path `%s`.', path) : require("fbjs/lib/invariant")(false) : void 0;
119
- }
120
- },
121
- getQuery: function getQuery(store, path, appendNode) {
122
- var child = appendNode;
123
- var prevField;
124
-
125
- var _ConnectionInterface$ = require("relay-runtime").ConnectionInterface.get(),
126
- EDGES = _ConnectionInterface$.EDGES;
127
-
128
- while (path.type === 'client') {
129
- var node = path.node;
130
-
131
- if (node instanceof require("./RelayQuery").Field) {
132
- var schemaName = node.getSchemaName();
133
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(!prevField || prevField !== EDGES || !node.isConnection(), 'RelayQueryPath.getQuery(): Cannot generate accurate query for ' + 'path with connection `%s`. Consider adding an `id` field to each ' + '`node` to make them refetchable.', schemaName) : void 0;
134
- prevField = schemaName;
135
- }
136
-
137
- var idFieldName = node instanceof require("./RelayQuery").Field ? node.getInferredPrimaryKey() : require("./RelayNodeInterface").ID;
138
-
139
- if (idFieldName) {
140
- child = node.clone([child, node.getFieldByStorageKey(idFieldName), node.getFieldByStorageKey(require("./RelayNodeInterface").TYPENAME)]);
141
- } else {
142
- child = node.clone([child]);
143
- }
144
-
145
- path = path.parent;
146
- }
147
-
148
- !(path.type !== 'rootRecord') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryPath: Attempted to construct a classic query, but the ' + 'record was initially fetched with new Relay APIs. Ensure that ' + 'deprecated components such as RelayContainer are not nested in ' + 'new APIs such as QueryRenderer or FragmentContainer.') : require("fbjs/lib/invariant")(false) : void 0;
149
- var root = path.type === 'root' ? path.root : createRootQueryFromNodePath(path);
150
- var children = [child, root.getFieldByStorageKey(require("./RelayNodeInterface").ID), root.getFieldByStorageKey(require("./RelayNodeInterface").TYPENAME)];
151
- var rootChildren = getRootFragmentForQuery(store, root, children);
152
- var pathQuery = root.cloneWithRoute(rootChildren, appendNode.getRoute()); // for flow
153
-
154
- !(pathQuery instanceof require("./RelayQuery").Root) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryPath: Expected the root of path `%s` to be a query.', RelayQueryPath.getName(path)) : require("fbjs/lib/invariant")(false) : void 0;
155
- return pathQuery;
156
- }
157
- };
158
-
159
- function createRootQueryFromNodePath(nodePath) {
160
- return require("./RelayQuery").Root.build(nodePath.name, require("./RelayNodeInterface").NODE, nodePath.dataID, [idField, typeField], {
161
- identifyingArgName: require("./RelayNodeInterface").ID,
162
- identifyingArgType: require("./RelayNodeInterface").ID_TYPE,
163
- isAbstract: true,
164
- isDeferred: false,
165
- isPlural: false
166
- }, require("./RelayNodeInterface").NODE_TYPE, nodePath.routeName);
167
- }
168
-
169
- function getRootFragmentForQuery(store, root, children) {
170
- var nextChildren = []; // $FlowIssue: Flow isn't recognizing that `filter(x => !!x)` returns a list
171
- // of non-null values.
172
-
173
- children.forEach(function (child) {
174
- if (child) {
175
- nextChildren.push(child);
176
- }
177
- });
178
-
179
- if (!root.isAbstract()) {
180
- // No need to wrap child nodes of a known concrete type.
181
- return nextChildren;
182
- }
183
-
184
- var identifyingArgKeys = [];
185
-
186
- require("./forEachRootCallArg")(root, function (_ref) {
187
- var identifyingArgKey = _ref.identifyingArgKey;
188
- identifyingArgKeys.push(identifyingArgKey);
189
- });
190
-
191
- var identifyingArgKey = identifyingArgKeys[0];
192
- var rootID = store.getDataID(root.getStorageKey(), identifyingArgKey);
193
- var rootType = rootID && store.getType(rootID);
194
-
195
- if (rootType != null) {
196
- return [require("./RelayQuery").Fragment.build(root.getName(), rootType, nextChildren)];
197
- } else {
198
- var rootState = rootID != null ? store.getRecordState(rootID) : require("./RelayClassicRecordState").UNKNOWN;
199
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayQueryPath: No typename found for %s record `%s`. Generating a ' + 'possibly invalid query.', rootState.toLowerCase(), rootID) : void 0;
200
- return nextChildren;
201
- }
202
- }
203
-
204
- module.exports = RelayQueryPath;
@@ -1,103 +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
- * Instances of these are made available via `RelayNetworkLayer.sendQueries`.
18
- */
19
- var RelayQueryRequest =
20
- /*#__PURE__*/
21
- function (_Deferred) {
22
- (0, _inheritsLoose2["default"])(RelayQueryRequest, _Deferred);
23
-
24
- function RelayQueryRequest(query) {
25
- var _this;
26
-
27
- _this = _Deferred.call(this) || this;
28
- _this._printedQuery = null;
29
- _this._query = query;
30
- return _this;
31
- }
32
- /**
33
- * @public
34
- *
35
- * Gets a string name used to refer to this request for printing debug output.
36
- */
37
-
38
-
39
- var _proto = RelayQueryRequest.prototype;
40
-
41
- _proto.getDebugName = function getDebugName() {
42
- var name = this._query.getName();
43
-
44
- return this._query.isDeferred() ? name + ' (DEFERRED)' : name;
45
- };
46
- /**
47
- * @public
48
- *
49
- * Gets a unique identifier for this query. These identifiers are useful for
50
- * assigning response payloads to their corresponding queries when sent in a
51
- * single GraphQL request.
52
- */
53
-
54
-
55
- _proto.getID = function getID() {
56
- return this._query.getID();
57
- };
58
-
59
- _proto._getPrintedQuery = function _getPrintedQuery() {
60
- var printedQuery = this._printedQuery;
61
-
62
- if (printedQuery == null) {
63
- printedQuery = this._query instanceof require("./RelayQuery").OSSQuery ? require("./printRelayOSSQuery")(this._query) : require("./printRelayQuery")(this._query);
64
- this._printedQuery = printedQuery;
65
- }
66
-
67
- return printedQuery;
68
- };
69
- /**
70
- * @public
71
- *
72
- * Gets the variables used by the query. These variables should be serialized
73
- * and sent in the GraphQL request.
74
- */
75
-
76
-
77
- _proto.getVariables = function getVariables() {
78
- return this._getPrintedQuery().variables;
79
- };
80
- /**
81
- * @public
82
- *
83
- * Gets a string representation of the GraphQL query.
84
- */
85
-
86
-
87
- _proto.getQueryString = function getQueryString() {
88
- return this._getPrintedQuery().text;
89
- };
90
- /**
91
- * @public
92
- * @unstable
93
- */
94
-
95
-
96
- _proto.getQuery = function getQuery() {
97
- return this._query;
98
- };
99
-
100
- return RelayQueryRequest;
101
- }(require("fbjs/lib/Deferred"));
102
-
103
- module.exports = RelayQueryRequest;
@@ -1,86 +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 _toConsumableArray2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
- var RelayQueryTracker =
15
- /*#__PURE__*/
16
- function () {
17
- function RelayQueryTracker() {
18
- this._trackedNodesByID = {};
19
- }
20
-
21
- var _proto = RelayQueryTracker.prototype;
22
-
23
- _proto.trackNodeForID = function trackNodeForID(node, dataID) {
24
- this._trackedNodesByID[dataID] = this._trackedNodesByID[dataID] || {
25
- trackedNodes: [],
26
- isMerged: false
27
- };
28
-
29
- this._trackedNodesByID[dataID].trackedNodes.push(node);
30
-
31
- this._trackedNodesByID[dataID].isMerged = false;
32
- };
33
- /**
34
- * Get the children that are tracked for the given `dataID`, if any.
35
- */
36
-
37
-
38
- _proto.getTrackedChildrenForID = function getTrackedChildrenForID(dataID) {
39
- var trackedNodesByID = this._trackedNodesByID[dataID];
40
-
41
- if (!trackedNodesByID) {
42
- return [];
43
- }
44
-
45
- var isMerged = trackedNodesByID.isMerged,
46
- trackedNodes = trackedNodesByID.trackedNodes;
47
-
48
- if (!isMerged) {
49
- var trackedChildren = [];
50
- trackedNodes.forEach(function (trackedQuery) {
51
- trackedChildren.push.apply(trackedChildren, (0, _toConsumableArray2["default"])(trackedQuery.getChildren()));
52
- });
53
- trackedNodes.length = 0;
54
- trackedNodesByID.isMerged = true;
55
-
56
- var containerNode = require("./RelayQuery").Fragment.build('RelayQueryTracker', require("./RelayNodeInterface").NODE_TYPE, trackedChildren);
57
-
58
- containerNode = require("./flattenRelayQuery")(containerNode);
59
-
60
- if (containerNode) {
61
- trackedNodes.push(containerNode);
62
- }
63
- }
64
-
65
- var trackedNode = trackedNodes[0];
66
-
67
- if (trackedNode) {
68
- return trackedNode.getChildren();
69
- }
70
-
71
- return [];
72
- };
73
- /**
74
- * Removes all nodes that are tracking the given DataID from the
75
- * query-tracker.
76
- */
77
-
78
-
79
- _proto.untrackNodesForID = function untrackNodesForID(dataID) {
80
- delete this._trackedNodesByID[dataID];
81
- };
82
-
83
- return RelayQueryTracker;
84
- }();
85
-
86
- module.exports = RelayQueryTracker;
@@ -1,91 +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
- * `RelayQueryTransform` is a `RelayQueryVisitor` subclass that simplifies the
18
- * process of traversing, filtering, or transforming a Relay Query.
19
- *
20
- * The traversal is a map operation from `RelayQuery` nodes to nodes. The
21
- * default implementation traverses all nodes and maps each one to its
22
- * original value (ie. a no-op).
23
- *
24
- * Just like `RelayQueryVisitor`, subclasses of `RelayQueryTransform` can
25
- * optionally implement methods to customize the traversal and mapping of
26
- * different RelayQuery node types:
27
- *
28
- * - `visitField(field, state)`: Returns the new value for the visited field, or
29
- * `null` to remove it from the output.
30
- * - `visitFragment(fragment, state)`: Returns the new value for the visited
31
- * fragment, or `null` to remove it from the output.
32
- * - `visitQuery(fragment, state)`: Returns the new value for the top-level
33
- * query, or `null` to transform the entire query out of existence.
34
- *
35
- * There are two additional methods for controlling the traversal:
36
- *
37
- * - `traverse(parent, state)`: Returns a cloned copy of the parent node after
38
- * processing all of its children. Does not clone if nothing changed.
39
- * - `visit(child, state)`: Processes the child node, calling the appropriate
40
- * `visit{Field,Fragment,Root` method based on the node type.
41
- *
42
- * All of these methods may return the original node in order to leave it
43
- * intact.
44
- *
45
- * @see RelayQueryVisitor
46
- */
47
- var RelayQueryTransform =
48
- /*#__PURE__*/
49
- function (_RelayQueryVisitor) {
50
- (0, _inheritsLoose2["default"])(RelayQueryTransform, _RelayQueryVisitor);
51
-
52
- function RelayQueryTransform() {
53
- return _RelayQueryVisitor.apply(this, arguments) || this;
54
- }
55
-
56
- var _proto = RelayQueryTransform.prototype;
57
-
58
- _proto.traverse = function traverse(node, nextState) {
59
- if (!node.canHaveSubselections()) {
60
- return node;
61
- }
62
-
63
- var nextChildren;
64
- this.traverseChildren(node, nextState, function (child, index, children) {
65
- var prevChild = children[index];
66
- var nextChild = this.visit(prevChild, nextState);
67
-
68
- if (nextChild !== prevChild) {
69
- nextChildren = nextChildren || children.slice(0, index);
70
- }
71
-
72
- if (nextChildren && nextChild) {
73
- nextChildren.push(nextChild);
74
- }
75
- }, this);
76
-
77
- if (nextChildren) {
78
- if (!nextChildren.length) {
79
- return null;
80
- }
81
-
82
- return node.clone(nextChildren);
83
- }
84
-
85
- return node;
86
- };
87
-
88
- return RelayQueryTransform;
89
- }(require("./RelayQueryVisitor"));
90
-
91
- module.exports = RelayQueryTransform;
@@ -1,93 +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
- * Base class for traversing a Relay Query.
16
- *
17
- * Subclasses can optionally implement methods to customize the traversal:
18
- *
19
- * - `visitField(field, state)`: Called for each field.
20
- * - `visitFragment(fragment, state)`: Called for each fragment.
21
- * - `visitQuery(fragment, state)`: Called for the top level query.
22
- *
23
- * A `state` variable is passed along to all callbacks and can be used to
24
- * accumulate data while traversing (effectively passing data back up the tree),
25
- * or modify the behavior of later callbacks (effectively passing data down the
26
- * tree).
27
- *
28
- * There are two additional methods for controlling the traversal:
29
- *
30
- * - `traverse(parent, state)`: Visits all children of `parent`. Subclasses
31
- * may override in order to short-circuit traversal. Note that
32
- * `visit{Field,Fragment,Query}` are //not// called on `parent`, as it will
33
- * already have been visited by the time this method is called.
34
- * - `visit(child, state)`: Processes the `child` node, calling the appropriate
35
- * `visit{Field,Fragment,Query}` method based on the node type.
36
- *
37
- * By convention, each of the callback methods returns the visited node. This is
38
- * used by the `RelayQueryTransform` subclass to implement mapping and filtering
39
- * behavior, but purely-visitor subclases do not need to follow this convention.
40
- *
41
- * @see RelayQueryTransform
42
- */
43
- var RelayQueryVisitor =
44
- /*#__PURE__*/
45
- function () {
46
- function RelayQueryVisitor() {}
47
-
48
- var _proto = RelayQueryVisitor.prototype;
49
-
50
- _proto.visit = function visit(node, nextState) {
51
- if (node instanceof require("./RelayQuery").Field) {
52
- return this.visitField(node, nextState);
53
- } else if (node instanceof require("./RelayQuery").Fragment) {
54
- return this.visitFragment(node, nextState);
55
- } else if (node instanceof require("./RelayQuery").Root) {
56
- return this.visitRoot(node, nextState);
57
- }
58
- };
59
-
60
- _proto.traverse = function traverse(node, nextState) {
61
- if (node.canHaveSubselections()) {
62
- this.traverseChildren(node, nextState, function (child) {
63
- this.visit(child, nextState);
64
- }, this);
65
- }
66
-
67
- return node;
68
- };
69
-
70
- _proto.traverseChildren = function traverseChildren(node, nextState, callback, context) {
71
- var children = node.getChildren();
72
-
73
- for (var _index = 0; _index < children.length; _index++) {
74
- callback.call(context, children[_index], _index, children);
75
- }
76
- };
77
-
78
- _proto.visitField = function visitField(node, nextState) {
79
- return this.traverse(node, nextState);
80
- };
81
-
82
- _proto.visitFragment = function visitFragment(node, nextState) {
83
- return this.traverse(node, nextState);
84
- };
85
-
86
- _proto.visitRoot = function visitRoot(node, nextState) {
87
- return this.traverse(node, nextState);
88
- };
89
-
90
- return RelayQueryVisitor;
91
- }();
92
-
93
- module.exports = RelayQueryVisitor;