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,75 +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
- * Compares `objectA` and `objectB` using the provided `isEqual` function.
14
- *
15
- * If a `filter` object is provided, only its keys will be checked during
16
- * comparison.
17
- */
18
- function compareObjects(isEqual, objectA, objectB, filter) {
19
- var key; // Test for A's keys different from B.
20
-
21
- for (key in objectA) {
22
- if (filter && !filter.hasOwnProperty(key)) {
23
- continue;
24
- }
25
-
26
- if (objectA.hasOwnProperty(key) && (!objectB.hasOwnProperty(key) || !isEqual(objectA[key], objectB[key], key))) {
27
- return false;
28
- }
29
- } // Test for B's keys missing from A.
30
-
31
-
32
- for (key in objectB) {
33
- if (filter && !filter.hasOwnProperty(key)) {
34
- continue;
35
- }
36
-
37
- if (objectB.hasOwnProperty(key) && !objectA.hasOwnProperty(key)) {
38
- return false;
39
- }
40
- }
41
-
42
- return true;
43
- }
44
-
45
- function isQueryDataEqual(fragmentPointers, currProp, nextProp, propName) {
46
- return (// resolved data did not change
47
- fragmentPointers[propName] && currProp === nextProp || // otherwise compare fake data
48
- require("relay-runtime").isScalarAndEqual(currProp, nextProp)
49
- );
50
- }
51
-
52
- function isNonQueryPropEqual(fragments, currProp, nextProp, propName) {
53
- return (// ignore props with fragments (instead resolved values are compared)
54
- fragments.hasOwnProperty(propName) || // otherwise props must be scalar and === in order to skip
55
- require("relay-runtime").isScalarAndEqual(currProp, nextProp)
56
- );
57
- }
58
- /**
59
- * Relay-aware comparators for props and state provide a reasonable default
60
- * implementation of `shouldComponentUpdate`.
61
- */
62
-
63
-
64
- var RelayContainerComparators = {
65
- areQueryResultsEqual: function areQueryResultsEqual(fragmentPointers, prevQueryData, nextQueryData) {
66
- return compareObjects(isQueryDataEqual.bind(null, fragmentPointers), prevQueryData, nextQueryData);
67
- },
68
- areNonQueryPropsEqual: function areNonQueryPropsEqual(fragments, props, nextProps) {
69
- return compareObjects(isNonQueryPropEqual.bind(null, fragments), props, nextProps);
70
- },
71
- areQueryVariablesEqual: function areQueryVariablesEqual(variables, nextVariables) {
72
- return compareObjects(require("relay-runtime").isScalarAndEqual, variables, nextVariables);
73
- }
74
- };
75
- module.exports = RelayContainerComparators;
@@ -1,21 +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
- * This feature is deprecated and unavailable in open source.
13
- */
14
-
15
- var RelayContainerProxy = {
16
- proxyMethods: function proxyMethods(Container, Component) {},
17
- injectProxyMethods: function injectProxyMethods(proxyMethods) {
18
- this.proxyMethods = proxyMethods;
19
- }
20
- };
21
- module.exports = RelayContainerProxy;
@@ -1,192 +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 RelayDefaultNetworkLayer =
15
- /*#__PURE__*/
16
- function () {
17
- // InitWithRetries
18
- function RelayDefaultNetworkLayer(uri, init) {
19
- this._uri = uri;
20
- this._init = (0, _objectSpread2["default"])({}, init); // Facilitate reuse when creating custom network layers.
21
-
22
- this.sendMutation = this.sendMutation.bind(this);
23
- this.sendQueries = this.sendQueries.bind(this);
24
- this.supports = this.supports.bind(this);
25
- }
26
-
27
- var _proto = RelayDefaultNetworkLayer.prototype;
28
-
29
- _proto.sendMutation = function sendMutation(request) {
30
- return this._sendMutation(request).then(function (result) {
31
- return result.json();
32
- }).then(function (payload) {
33
- if (payload.hasOwnProperty('errors')) {
34
- var error = createRequestError(request, '200', payload);
35
- request.reject(error);
36
- } else {
37
- request.resolve({
38
- response: payload.data
39
- });
40
- }
41
- })["catch"](function (error) {
42
- return request.reject(error);
43
- });
44
- };
45
-
46
- _proto.sendQueries = function sendQueries(requests) {
47
- var _this = this;
48
-
49
- return Promise.all(requests.map(function (request) {
50
- return _this._sendQuery(request).then(function (result) {
51
- return result.json();
52
- }).then(function (payload) {
53
- if (payload.hasOwnProperty('errors')) {
54
- var error = createRequestError(request, '200', payload);
55
- request.reject(error);
56
- } else if (!payload.hasOwnProperty('data')) {
57
- request.reject(new Error('Server response was missing for query ' + "`".concat(request.getDebugName(), "`.")));
58
- } else {
59
- request.resolve({
60
- response: payload.data
61
- });
62
- }
63
- })["catch"](function (error) {
64
- return request.reject(error);
65
- });
66
- }));
67
- };
68
-
69
- _proto.supports = function supports() {
70
- // Does not support the only defined option, "defer".
71
- return false;
72
- };
73
- /**
74
- * Sends a POST request with optional files.
75
- */
76
-
77
-
78
- _proto._sendMutation = function _sendMutation(request) {
79
- var init;
80
- var files = request.getFiles();
81
-
82
- if (files) {
83
- if (!global.FormData) {
84
- throw new Error('Uploading files without `FormData` not supported.');
85
- }
86
-
87
- var formData = new FormData();
88
- formData.append('query', request.getQueryString());
89
- formData.append('variables', JSON.stringify(request.getVariables()));
90
-
91
- for (var filename in files) {
92
- if (files.hasOwnProperty(filename)) {
93
- formData.append(filename, files[filename]);
94
- }
95
- }
96
-
97
- init = (0, _objectSpread2["default"])({}, this._init, {
98
- body: formData,
99
- method: 'POST'
100
- });
101
- } else {
102
- init = (0, _objectSpread2["default"])({}, this._init, {
103
- body: JSON.stringify({
104
- query: request.getQueryString(),
105
- variables: request.getVariables()
106
- }),
107
- headers: (0, _objectSpread2["default"])({}, this._init.headers, {
108
- Accept: '*/*',
109
- 'Content-Type': 'application/json'
110
- }),
111
- method: 'POST'
112
- });
113
- }
114
-
115
- return require("fbjs/lib/fetch")(this._uri, init).then(function (response) {
116
- return throwOnServerError(request, response);
117
- });
118
- };
119
- /**
120
- * Sends a POST request and retries if the request fails or times out.
121
- */
122
-
123
-
124
- _proto._sendQuery = function _sendQuery(request) {
125
- return require("fbjs/lib/fetchWithRetries")(this._uri, (0, _objectSpread2["default"])({}, this._init, {
126
- body: JSON.stringify({
127
- query: request.getQueryString(),
128
- variables: request.getVariables()
129
- }),
130
- headers: (0, _objectSpread2["default"])({}, this._init.headers, {
131
- Accept: '*/*',
132
- 'Content-Type': 'application/json'
133
- }),
134
- method: 'POST'
135
- }));
136
- };
137
-
138
- return RelayDefaultNetworkLayer;
139
- }();
140
- /**
141
- * Rejects HTTP responses with a status code that is not >= 200 and < 300.
142
- * This is done to follow the internal behavior of `fetchWithRetries`.
143
- */
144
-
145
-
146
- function throwOnServerError(request, response) {
147
- if (response.status >= 200 && response.status < 300) {
148
- return response;
149
- } else {
150
- return response.text().then(function (payload) {
151
- throw createRequestError(request, response.status, payload);
152
- });
153
- }
154
- }
155
- /**
156
- * Formats an error response from GraphQL server request.
157
- */
158
-
159
-
160
- function formatRequestErrors(request, errors) {
161
- var CONTEXT_BEFORE = 20;
162
- var CONTEXT_LENGTH = 60;
163
- var queryLines = request.getQueryString().split('\n');
164
- return errors.map(function (_ref, ii) {
165
- var locations = _ref.locations,
166
- message = _ref.message;
167
- var prefix = ii + 1 + '. ';
168
- var indent = ' '.repeat(prefix.length); //custom errors thrown in graphql-server may not have locations
169
-
170
- var locationMessage = locations ? '\n' + locations.map(function (_ref2) {
171
- var column = _ref2.column,
172
- line = _ref2.line;
173
- var queryLine = queryLines[line - 1];
174
- var offset = Math.min(column - 1, CONTEXT_BEFORE);
175
- return [queryLine.substr(column - 1 - offset, CONTEXT_LENGTH), ' '.repeat(Math.max(0, offset)) + '^^^'].map(function (messageLine) {
176
- return indent + messageLine;
177
- }).join('\n');
178
- }).join('\n') : '';
179
- return prefix + message + locationMessage;
180
- }).join('\n');
181
- }
182
-
183
- function createRequestError(request, responseStatus, payload) {
184
- var requestType = request instanceof require("./RelayMutationRequest") ? 'mutation' : 'query';
185
- var errorReason = typeof payload === 'object' ? formatRequestErrors(request, payload.errors) : "Server response had an error status: ".concat(responseStatus);
186
- var error = new Error("Server request for ".concat(requestType, " `").concat(request.getDebugName(), "` ") + "failed for the following reasons:\n\n".concat(errorReason));
187
- error.source = payload;
188
- error.status = responseStatus;
189
- return error;
190
- }
191
-
192
- module.exports = RelayDefaultNetworkLayer;