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,112 +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
- */
11
- 'use strict';
12
- /* eslint-disable no-shadow */
13
-
14
- /**
15
- * @internal
16
- *
17
- * Determines whether the edit distance between two strings is at or below the
18
- * specified threshold distance, using the approach described by Ukkonen (1985)
19
- * in "Algorithms for Approximate String Matching"[0] and then improved upon by
20
- * Berghel and Roach (1996) in "An Extension of Ukkonen's Enhanced Dynamic
21
- * Programming ASM Algorithm"[1].
22
- *
23
- * Given two strings of length `m` and `n` respectively, and threshold `t`,
24
- * uses `O(t*min(m,n))` time and `O(min(t,m,n))` space.
25
- *
26
- * @see [0]: http://www.cs.helsinki.fi/u/ukkonen/InfCont85.PDF
27
- * @see [1]: http://berghel.net/publications/asm/asm.pdf
28
- */
29
-
30
- function testEditDistance(a, b, threshold) {
31
- // Ensure `b` is at least as long as `a`, swapping if necessary.
32
- var m = a.length;
33
- var n = b.length;
34
-
35
- if (n < m) {
36
- var _ref = [m, n];
37
- n = _ref[0];
38
- m = _ref[1];
39
- var _ref2 = [a, b];
40
- b = _ref2[0];
41
- a = _ref2[1];
42
- }
43
-
44
- if (!m) {
45
- return n <= threshold;
46
- }
47
-
48
- var zeroK = n;
49
- var maxK = zeroK * 2 + 1;
50
- var fkp = Array.from(Array(maxK), function () {
51
- return [];
52
- });
53
-
54
- for (var k = -zeroK; k < 0; k++) {
55
- var _p = -k - 1;
56
-
57
- fkp[k + zeroK][_p + 1] = -k - 1;
58
- fkp[k + zeroK][_p] = -Infinity;
59
- }
60
-
61
- fkp[zeroK][0] = -1;
62
-
63
- for (var _k = 1; _k <= zeroK; _k++) {
64
- var _p2 = _k - 1;
65
-
66
- fkp[_k + zeroK][_p2 + 1] = -1;
67
- fkp[_k + zeroK][_p2] = -Infinity;
68
- } // This loop is the alternative form suggested in the afterword of Berghel &
69
- // Roach.
70
-
71
-
72
- var p = n - m - 1;
73
-
74
- do {
75
- if (p > threshold) {
76
- return false;
77
- }
78
-
79
- p++;
80
-
81
- for (var i = Math.floor((p - (n - m)) / 2); i >= 1; i--) {
82
- f(n - m + i, p - i);
83
- }
84
-
85
- for (var _i = Math.floor((n - m + p) / 2); _i >= 1; _i--) {
86
- f(n - m - _i, p - _i);
87
- }
88
-
89
- f(n - m, p);
90
- } while (fkp[n - m + zeroK][p] !== m);
91
-
92
- return true;
93
-
94
- function f(k, p) {
95
- var t = fkp[k + zeroK][p] + 1;
96
- var t2 = t; // Check for transposed characters.
97
-
98
- if (a[t - 1] === b[k + t] && a[t] === b[k + t - 1]) {
99
- t2 = t + 1;
100
- }
101
-
102
- t = Math.max(t, fkp[k - 1 + zeroK][p], fkp[k + 1 + zeroK][p] + 1, t2);
103
-
104
- while (a[t] === b[t + k] && t < Math.min(m, n - k)) {
105
- t++;
106
- }
107
-
108
- fkp[k + zeroK][p + 1] = t;
109
- }
110
- }
111
-
112
- module.exports = testEditDistance;
@@ -1,26 +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
- * This function is used in place of the non-standard promise.done() method.
13
- * However, this is an anti-pattern as any function which operates on a Promise
14
- * should instead consider returning that Promise for the caller to handle
15
- * failure itself.
16
- */
17
-
18
- function throwFailedPromise(promise) {
19
- promise.then(undefined, function (error) {
20
- return setTimeout(function () {
21
- throw error;
22
- }, 0);
23
- });
24
- }
25
-
26
- module.exports = throwFailedPromise;
package/lib/toGraphQL.js DELETED
@@ -1,94 +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
- /**
13
- * @internal
14
- *
15
- * Converts a RelayQuery.Node into a plain object representation. This is
16
- * equivalent to the AST produced by `babel-plugin-relay` and is intended for
17
- * use in serializing RelayQuery nodes.
18
- *
19
- * NOTE: This is used by external open source projects.
20
- */
21
- var toGraphQL = {
22
- Query: function Query(node) {
23
- var batchCall = node.getBatchCall();
24
- var identifyingArgValue;
25
-
26
- if (batchCall) {
27
- identifyingArgValue = require("./QueryBuilder").createBatchCallVariable(batchCall.sourceQueryID, batchCall.sourceQueryPath);
28
- } else {
29
- var identifyingArg = node.getIdentifyingArg();
30
-
31
- if (identifyingArg) {
32
- if (Array.isArray(identifyingArg.value)) {
33
- identifyingArgValue = identifyingArg.value.map(require("./QueryBuilder").createCallValue);
34
- } else {
35
- identifyingArgValue = require("./QueryBuilder").createCallValue(identifyingArg.value);
36
- }
37
- }
38
- }
39
-
40
- var children = node.getChildren().map(toGraphQLSelection); // Use `QueryBuilder` to generate the correct calls from the
41
- // identifying argument & metadata.
42
-
43
- return require("./QueryBuilder").createQuery({
44
- children: children,
45
- fieldName: node.getFieldName(),
46
- identifyingArgValue: identifyingArgValue,
47
- isDeferred: node.isDeferred(),
48
- metadata: node.getConcreteQueryNode().metadata,
49
- name: node.getName(),
50
- type: node.getType()
51
- });
52
- },
53
- Fragment: function Fragment(node) {
54
- var children = node.getChildren().map(toGraphQLSelection);
55
- var fragment = {
56
- children: children,
57
- id: require("./generateConcreteFragmentID")(),
58
- kind: 'Fragment',
59
- metadata: {
60
- isAbstract: node.isAbstract(),
61
- plural: node.isPlural()
62
- },
63
- name: node.getDebugName(),
64
- type: node.getType()
65
- };
66
- return fragment;
67
- },
68
- Field: function Field(node) {
69
- var calls = require("./callsToGraphQL")(node.getCallsWithValues());
70
-
71
- var children = node.getChildren().map(toGraphQLSelection);
72
- var field = {
73
- alias: node.getConcreteQueryNode().alias,
74
- calls: calls,
75
- children: children,
76
- fieldName: node.getSchemaName(),
77
- kind: 'Field',
78
- metadata: node.getConcreteQueryNode().metadata,
79
- type: node.getType()
80
- };
81
- return field;
82
- }
83
- };
84
-
85
- function toGraphQLSelection(node) {
86
- if (node instanceof require("./RelayQuery").Fragment) {
87
- return toGraphQL.Fragment(node);
88
- } else {
89
- !(node instanceof require("./RelayQuery").Field) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'toGraphQL: Invalid node.') : require("fbjs/lib/invariant")(false) : void 0;
90
- return toGraphQL.Field(node);
91
- }
92
- }
93
-
94
- module.exports = toGraphQL;
@@ -1,145 +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
- * Transforms "client" payloads with property keys that match the "application"
16
- * names (i.e. property names are schema names or aliases) into "server"
17
- * payloads that match what the server would return for the given query (i.e.
18
- * property names are serialization keys instead).
19
- */
20
- function transformRelayQueryPayload(root, clientData, config) {
21
- if (clientData == null) {
22
- return clientData;
23
- } else {
24
- return require("fbjs/lib/mapObject")(clientData, function (item) {
25
- // Handle both FB & OSS formats for root payloads on plural calls: FB
26
- // returns objects, OSS returns arrays.
27
- if (Array.isArray(item)) {
28
- return item.map(function (innerItem) {
29
- return transform(root, innerItem, config);
30
- });
31
- }
32
-
33
- return transform(root, item, config);
34
- });
35
- }
36
- }
37
-
38
- function transform(root, clientData, config) {
39
- if (clientData == null) {
40
- return clientData;
41
- }
42
-
43
- var transformer = new RelayPayloadTransformer(config);
44
- var serverData = {};
45
- transformer.visit(root, {
46
- client: clientData,
47
- server: serverData
48
- });
49
- return serverData;
50
- }
51
-
52
- var RelayPayloadTransformer =
53
- /*#__PURE__*/
54
- function (_RelayQueryVisitor) {
55
- (0, _inheritsLoose2["default"])(RelayPayloadTransformer, _RelayQueryVisitor);
56
-
57
- function RelayPayloadTransformer(config) {
58
- var _this;
59
-
60
- _this = _RelayQueryVisitor.call(this) || this;
61
-
62
- if (config) {
63
- _this._getKeyForClientData = config.getKeyForClientData;
64
- _this._traverseChildren = config.traverseChildren;
65
- }
66
-
67
- return _this;
68
- }
69
-
70
- var _proto = RelayPayloadTransformer.prototype;
71
-
72
- _proto._getKeyForClientData = function _getKeyForClientData(field) {
73
- return field.getApplicationName();
74
- };
75
-
76
- _proto.traverseChildren = function traverseChildren(node, nextState, callback, context) {
77
- if (this._traverseChildren) {
78
- this._traverseChildren(node, callback, context);
79
- } else {
80
- _RelayQueryVisitor.prototype.traverseChildren.call(this, node, nextState, callback, context);
81
- }
82
- };
83
-
84
- _proto.visitField = function visitField(node, state) {
85
- var _this2 = this;
86
-
87
- var client = state.client,
88
- server = state.server;
89
-
90
- var applicationName = this._getKeyForClientData(node);
91
-
92
- var serializationKey = node.getSerializationKey();
93
- var clientData = client[applicationName];
94
- var serverData = server[serializationKey];
95
-
96
- if (!client.hasOwnProperty(applicationName)) {
97
- return;
98
- } else if (!node.canHaveSubselections() || clientData == null) {
99
- server[serializationKey] = clientData;
100
- } else if (Array.isArray(clientData)) {
101
- if (serverData == null) {
102
- server[serializationKey] = serverData = [];
103
- }
104
-
105
- clientData.forEach(function (clientItem, index) {
106
- !Array.isArray(serverData) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayPayloadTransformer: Got conflicting values for field `%s`: ' + 'expected values to be arrays.', applicationName) : require("fbjs/lib/invariant")(false) : void 0;
107
-
108
- if (clientItem == null) {
109
- serverData[index] = clientItem;
110
- return;
111
- }
112
-
113
- var serverItem = serverData && serverData[index];
114
-
115
- if (serverItem == null) {
116
- serverData[index] = serverItem = {};
117
- }
118
- /* $FlowFixMe - Flow error detected during the deployment of v0.38.0. To
119
- * see the error, remove this comment and run flow */
120
-
121
-
122
- _this2.traverse(node, {
123
- client: clientItem,
124
- server: serverItem
125
- });
126
- });
127
- } else {
128
- !(typeof clientData === 'object' && clientData !== null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayPayloadTransformer: Expected an object value for field `%s`.', applicationName) : require("fbjs/lib/invariant")(false) : void 0;
129
- !(serverData == null || typeof serverData === 'object') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayPayloadTransformer: Got conflicting values for field `%s`: ' + 'expected values to be objects.', applicationName) : require("fbjs/lib/invariant")(false) : void 0;
130
-
131
- if (serverData == null) {
132
- server[serializationKey] = serverData = {};
133
- }
134
-
135
- this.traverse(node, {
136
- client: clientData,
137
- server: serverData
138
- });
139
- }
140
- };
141
-
142
- return RelayPayloadTransformer;
143
- }(require("./RelayQueryVisitor"));
144
-
145
- module.exports = transformRelayQueryPayload;
@@ -1,117 +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 FUZZY_THRESHOLD = 3;
13
- /* eslint-disable no-unused-vars */
14
-
15
- var DEPRECATED = Object.freeze({
16
- assert: require("fbjs/lib/warning"),
17
- message: 'has deprecated property',
18
- type: 'DEPRECATED'
19
- });
20
- /* eslint-enable no-unused-vars */
21
-
22
- var OPTIONAL = Object.freeze({
23
- // These first two properties are not needed, but including them is easier
24
- // than getting Flow to accept a disjoint union.
25
- assert: function assert() {},
26
- message: '',
27
- type: 'OPTIONAL'
28
- });
29
- var REQUIRED = {
30
- assert: require("fbjs/lib/invariant"),
31
- message: 'must have property',
32
- type: 'REQUIRED'
33
- };
34
-
35
- function validateMutationConfig(config, name) {
36
- function assertValid(properties) {
37
- // Check for unexpected properties.
38
- Object.keys(config).forEach(function (property) {
39
- if (property === 'type') {
40
- return;
41
- }
42
-
43
- if (!properties.hasOwnProperty(property)) {
44
- var message = require("fbjs/lib/sprintf")('validateMutationConfig: Unexpected key `%s` in `%s` config ' + 'for `%s`', property, config.type, name);
45
-
46
- var suggestion = Object.keys(properties).find(function (candidate) {
47
- return require("./testEditDistance")(candidate, property, FUZZY_THRESHOLD);
48
- });
49
-
50
- if (suggestion) {
51
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, '%s; did you mean `%s`?', message, suggestion) : require("fbjs/lib/invariant")(false) : void 0;
52
- } else {
53
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, '%s.', message) : require("fbjs/lib/invariant")(false) : void 0;
54
- }
55
- }
56
- }); // Check for deprecated and missing properties.
57
-
58
- Object.keys(properties).forEach(function (property) {
59
- var validator = properties[property];
60
- var isRequired = validator.type === 'REQUIRED';
61
- var isDeprecated = validator.type === 'DEPRECATED';
62
- var present = config.hasOwnProperty(property);
63
-
64
- if (isRequired && !present || isDeprecated && present) {
65
- validator.assert(false, 'validateMutationConfig: `%s` config on `%s` %s `%s`.', config.type, name, validator.message, property);
66
- }
67
- });
68
- }
69
-
70
- switch (config.type) {
71
- case 'FIELDS_CHANGE':
72
- assertValid({
73
- fieldIDs: REQUIRED
74
- });
75
- break;
76
-
77
- case 'RANGE_ADD':
78
- assertValid({
79
- connectionName: REQUIRED,
80
- edgeName: REQUIRED,
81
- parentID: OPTIONAL,
82
- parentName: OPTIONAL,
83
- rangeBehaviors: REQUIRED
84
- });
85
- break;
86
-
87
- case 'NODE_DELETE':
88
- assertValid({
89
- connectionName: REQUIRED,
90
- deletedIDFieldName: REQUIRED,
91
- parentID: OPTIONAL,
92
- parentName: REQUIRED
93
- });
94
- break;
95
-
96
- case 'RANGE_DELETE':
97
- assertValid({
98
- connectionName: REQUIRED,
99
- deletedIDFieldName: REQUIRED,
100
- parentID: OPTIONAL,
101
- parentName: REQUIRED,
102
- pathToConnection: REQUIRED
103
- });
104
- break;
105
-
106
- case 'REQUIRED_CHILDREN':
107
- assertValid({
108
- children: REQUIRED
109
- });
110
- break;
111
-
112
- default:
113
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'validateMutationConfig: unknown config type `%s` on `%s`', config.type, name) : require("fbjs/lib/invariant")(false) : void 0;
114
- }
115
- }
116
-
117
- module.exports = validateMutationConfig;
@@ -1,112 +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
- var validateRelayReadQuery = require("fbjs/lib/emptyFunction");
15
-
16
- if (process.env.NODE_ENV !== "production") {
17
- // Wrap in an IIFE to avoid unwanted function hoisting.
18
- (function () {
19
- /**
20
- * @internal
21
- *
22
- * `validateRelayReadQuery` is a `__DEV__`-only validator that checks that a
23
- * query used to read data from `RelayStore` is well-formed. Validation
24
- * problems are reported via `console.error`.
25
- *
26
- * At the moment, "well-formed" means that the query does not contain
27
- * duplicate aliases.
28
- */
29
- validateRelayReadQuery = function _validateRelayReadQuery(queryNode, options) {
30
- var validator = new RelayStoreReadValidator(options);
31
- validator.visit(queryNode, {
32
- children: {},
33
- hash: null
34
- });
35
- };
36
- /**
37
- * Returns the nested AliasMap for `node`, initializing if it necessary.
38
- */
39
-
40
-
41
- function getAliasMap(node, parentAliasMap) {
42
- var applicationName = node.getApplicationName();
43
- var hash = node.getShallowHash();
44
- var children = parentAliasMap.children;
45
-
46
- if (!children.hasOwnProperty(applicationName)) {
47
- children[applicationName] = {
48
- children: {},
49
- hash: hash
50
- };
51
- } else if (children[applicationName].hash !== hash) {
52
- console.error('`%s` is used as an alias more than once. Please use unique aliases.', applicationName);
53
- }
54
-
55
- return children[applicationName];
56
- }
57
-
58
- var RelayStoreReadValidator =
59
- /*#__PURE__*/
60
- function (_RelayQueryVisitor) {
61
- (0, _inheritsLoose2["default"])(RelayStoreReadValidator, _RelayQueryVisitor);
62
-
63
- function RelayStoreReadValidator(options) {
64
- var _this;
65
-
66
- _this = _RelayQueryVisitor.call(this) || this;
67
- _this._traverseFragmentReferences = options && options.traverseFragmentReferences || false;
68
- return _this;
69
- }
70
-
71
- var _proto = RelayStoreReadValidator.prototype;
72
-
73
- _proto.visitField = function visitField(node, parentAliasMap) {
74
- var aliasMap = getAliasMap(node, parentAliasMap);
75
-
76
- if (node.isGenerated()) {
77
- return;
78
- } else if (!node.canHaveSubselections()) {
79
- return;
80
- } else if (node.isPlural()) {
81
- this._readPlural(node, aliasMap);
82
- } else {
83
- // No special handling needed for connections, edges, page_info etc.
84
- this._readLinkedField(node, aliasMap);
85
- }
86
- };
87
-
88
- _proto.visitFragment = function visitFragment(node, aliasMap) {
89
- if (this._traverseFragmentReferences || !node.isContainerFragment()) {
90
- this.traverse(node, aliasMap);
91
- }
92
- };
93
-
94
- _proto._readPlural = function _readPlural(node, aliasMap) {
95
- var _this2 = this;
96
-
97
- node.getChildren().forEach(function (child) {
98
- return _this2.visit(child, aliasMap);
99
- });
100
- };
101
-
102
- _proto._readLinkedField = function _readLinkedField(node, aliasMap) {
103
- aliasMap = getAliasMap(node, aliasMap);
104
- this.traverse(node, aliasMap);
105
- };
106
-
107
- return RelayStoreReadValidator;
108
- }(require("./RelayQueryVisitor"));
109
- })();
110
- }
111
-
112
- module.exports = validateRelayReadQuery;
@@ -1,44 +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
- /**
13
- * @internal
14
- *
15
- * Traverses a query and payload in parallel, writing the results into the
16
- * store.
17
- */
18
- function writeRelayQueryPayload(writer, query, payload) {
19
- var store = writer.getRecordStore();
20
- var recordWriter = writer.getRecordWriter();
21
-
22
- var path = require("./RelayQueryPath").create(query);
23
-
24
- require("./RelayNodeInterface").getResultsFromPayload(query, payload).forEach(function (_ref) {
25
- var result = _ref.result,
26
- rootCallInfo = _ref.rootCallInfo;
27
- var storageKey = rootCallInfo.storageKey,
28
- identifyingArgKey = rootCallInfo.identifyingArgKey;
29
- var dataID;
30
-
31
- if (typeof result === 'object' && result && typeof result[require("./RelayNodeInterface").ID] === 'string') {
32
- dataID = result[require("./RelayNodeInterface").ID];
33
- }
34
-
35
- if (dataID == null) {
36
- dataID = store.getDataID(storageKey, identifyingArgKey) || require("./generateClientID")();
37
- }
38
-
39
- recordWriter.putDataID(storageKey, identifyingArgKey, dataID);
40
- writer.writePayload(query, dataID, result, path);
41
- });
42
- }
43
-
44
- module.exports = require("relay-runtime").RelayProfiler.instrument('writeRelayQueryPayload', writeRelayQueryPayload);