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,113 +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
- // Maintains a map from the client id to the server id of
13
- // optimistically added nodes
14
- var clientIDToServerIDMap = {}; // For node-create mutations, maintains an index of the mutation to the
15
- // client ID of an optimistically created node (if it exists).
16
-
17
- var mutationIDToClientNodeIDMap = {}; // For mutations that have errors, maintains a two-directional index of the
18
- // mutation and node with an error.
19
-
20
- var clientMutationIDToErrorNodeID = {};
21
- var clientNodeIDToErrorMutationID = {};
22
- /**
23
- * @internal
24
- *
25
- * Records the client ID and error status of mutations as well as maintaining
26
- * a mapping of optimistic client IDs to server IDs.
27
- */
28
-
29
- var RelayMutationTracker = {
30
- /**
31
- * Checks if the given id represents an object only known on the client side
32
- * or not. In this case, it is both a client id and does not have a
33
- * corresponding mapping in the client server id map.
34
- */
35
- isClientOnlyID: function isClientOnlyID(dataID) {
36
- return require("./RelayRecord").isClientID(dataID) && !clientIDToServerIDMap[dataID];
37
- },
38
-
39
- /**
40
- * Updates the map from the client id to the server id for optimistically
41
- * added nodes.
42
- */
43
- updateClientServerIDMap: function updateClientServerIDMap(clientID, serverID) {
44
- clientIDToServerIDMap[clientID] = serverID;
45
- },
46
-
47
- /**
48
- * Gets the serverID (if one exists) for a given clientID
49
- */
50
- getServerIDForClientID: function getServerIDForClientID(clientID) {
51
- return clientIDToServerIDMap[clientID] || null;
52
- },
53
-
54
- /**
55
- * Record the root node ID associated with the mutation.
56
- */
57
- putClientIDForMutation: function putClientIDForMutation(clientID, clientMutationID) {
58
- mutationIDToClientNodeIDMap[clientMutationID] = clientID; // if an error exists for this mutation ID, remove the error on the previous
59
- // client ID and 'move' the error on the new client ID
60
-
61
- var errorNodeID = RelayMutationTracker.getErrorNodeForMutation(clientMutationID);
62
-
63
- if (errorNodeID) {
64
- RelayMutationTracker.deleteMutationForErrorNode(errorNodeID);
65
- RelayMutationTracker.putErrorNodeForMutation(clientID, clientMutationID);
66
- }
67
- },
68
-
69
- /**
70
- * Get the root record ID associated with the muation.
71
- */
72
- getClientIDForMutation: function getClientIDForMutation(clientMutationID) {
73
- return mutationIDToClientNodeIDMap[clientMutationID];
74
- },
75
-
76
- /**
77
- * Delete the root record ID associated with the mutation.
78
- */
79
- deleteClientIDForMutation: function deleteClientIDForMutation(clientMutationID) {
80
- delete mutationIDToClientNodeIDMap[clientMutationID];
81
- },
82
-
83
- /**
84
- * Record that an error occurred while creating the given (client) record ID.
85
- */
86
- putErrorNodeForMutation: function putErrorNodeForMutation(clientID, clientMutationID) {
87
- clientNodeIDToErrorMutationID[clientID] = clientMutationID;
88
- clientMutationIDToErrorNodeID[clientMutationID] = clientID;
89
- },
90
-
91
- /**
92
- * Find the failed mutation that created the given (client) record ID,
93
- * if any.
94
- */
95
- getMutationForErrorNode: function getMutationForErrorNode(clientID) {
96
- return clientNodeIDToErrorMutationID[clientID];
97
- },
98
-
99
- /**
100
- * Find the (client) ID of the record associated with the given mutation,
101
- * if any.
102
- */
103
- getErrorNodeForMutation: function getErrorNodeForMutation(clientMutationID) {
104
- return clientMutationIDToErrorNodeID[clientMutationID];
105
- },
106
- deleteMutationForErrorNode: function deleteMutationForErrorNode(clientID) {
107
- delete clientNodeIDToErrorMutationID[clientID];
108
- },
109
- deleteErrorNodeForMutation: function deleteErrorNodeForMutation(clientMutationID) {
110
- delete clientMutationIDToErrorNodeID[clientMutationID];
111
- }
112
- };
113
- module.exports = RelayMutationTracker;
@@ -1,92 +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 _defineProperty2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/defineProperty"));
13
-
14
- /**
15
- * @internal
16
- */
17
- var RelayMutationTransaction =
18
- /*#__PURE__*/
19
- function () {
20
- function RelayMutationTransaction(mutationQueue, id) {
21
- (0, _defineProperty2["default"])(this, "_rolledBack", false);
22
- this._id = id;
23
- this._mutationQueue = mutationQueue;
24
- }
25
- /**
26
- * Applies the transaction to the local store (ie. as an optimistic update).
27
- *
28
- * Returns itself so as to provide a "fluent interface".
29
- */
30
-
31
-
32
- var _proto = RelayMutationTransaction.prototype;
33
-
34
- _proto.applyOptimistic = function applyOptimistic() {
35
- var status = this.getStatus();
36
- !(status === require("./RelayMutationTransactionStatus").CREATED) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationTransaction: Only transactions with status `CREATED` ' + 'can be applied.') : require("fbjs/lib/invariant")(false) : void 0;
37
-
38
- this._mutationQueue.applyOptimistic(this._id);
39
-
40
- return this;
41
- };
42
- /**
43
- * Commits the transaction (ie. performs a server update).
44
- *
45
- * Returns itself so as to provide a "fluent interface".
46
- */
47
-
48
-
49
- _proto.commit = function commit() {
50
- var status = this.getStatus();
51
- !(status === require("./RelayMutationTransactionStatus").CREATED || status === require("./RelayMutationTransactionStatus").UNCOMMITTED) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationTransaction: Only transactions with status `CREATED` or ' + '`UNCOMMITTED` can be committed.') : require("fbjs/lib/invariant")(false) : void 0;
52
-
53
- this._mutationQueue.commit(this._id);
54
-
55
- return this;
56
- };
57
-
58
- _proto.recommit = function recommit() {
59
- var status = this.getStatus();
60
- !(status === require("./RelayMutationTransactionStatus").COLLISION_COMMIT_FAILED || status === require("./RelayMutationTransactionStatus").COMMIT_FAILED || status === require("./RelayMutationTransactionStatus").CREATED) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationTransaction: Only transaction with status ' + '`CREATED`, `COMMIT_FAILED`, or `COLLISION_COMMIT_FAILED` can be ' + 'recomitted.') : require("fbjs/lib/invariant")(false) : void 0;
61
-
62
- this._mutationQueue.commit(this._id);
63
- };
64
-
65
- _proto.rollback = function rollback() {
66
- var status = this.getStatus();
67
- !(status === require("./RelayMutationTransactionStatus").COLLISION_COMMIT_FAILED || status === require("./RelayMutationTransactionStatus").COMMIT_FAILED || status === require("./RelayMutationTransactionStatus").COMMIT_QUEUED || status === require("./RelayMutationTransactionStatus").CREATED || status === require("./RelayMutationTransactionStatus").UNCOMMITTED) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationTransaction: Only transactions with status `CREATED`, ' + '`UNCOMMITTED`, `COMMIT_FAILED`, `COLLISION_COMMIT_FAILED`, or ' + '`COMMIT_QUEUED` can be rolled back.') : require("fbjs/lib/invariant")(false) : void 0;
68
- this._rolledBack = true;
69
-
70
- this._mutationQueue.rollback(this._id);
71
- };
72
-
73
- _proto.getError = function getError() {
74
- return this._mutationQueue.getError(this._id);
75
- };
76
-
77
- _proto.getStatus = function getStatus() {
78
- return this._rolledBack ? require("./RelayMutationTransactionStatus").ROLLED_BACK : this._mutationQueue.getStatus(this._id);
79
- };
80
-
81
- _proto.getHash = function getHash() {
82
- return "".concat(this._id, ":").concat(this.getStatus());
83
- };
84
-
85
- _proto.getID = function getID() {
86
- return this._id;
87
- };
88
-
89
- return RelayMutationTransaction;
90
- }();
91
-
92
- module.exports = RelayMutationTransaction;
@@ -1,55 +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 RelayMutationTransactionStatus = {
13
- /**
14
- * Transaction has been created but an optimistic update has not been applied.
15
- * Transaction can be applied (optimistic) or committed (sent to server).
16
- */
17
- CREATED: 'CREATED',
18
-
19
- /**
20
- * Transaction hasn't yet been sent to the server. Client has an optimistic
21
- * update applied if the mutation defined one. Transaction can be committed or
22
- * rolled back.
23
- */
24
- UNCOMMITTED: 'UNCOMMITTED',
25
-
26
- /**
27
- * Transaction was committed but another transaction with the same collision
28
- * key is pending, so the transaction has been queued to send to the server.
29
- */
30
- COMMIT_QUEUED: 'COMMIT_QUEUED',
31
-
32
- /**
33
- * Transaction was queued for commit but another transaction with the same
34
- * collision queue failed to commit. All transactions in the collision
35
- * queue, including this one, have been failed as well. Transaction can be
36
- * recommitted or rolled back.
37
- */
38
- COLLISION_COMMIT_FAILED: 'COLLISION_COMMIT_FAILED',
39
-
40
- /**
41
- * Transaction was sent to the server for comitting and a response is awaited.
42
- */
43
- COMMITTING: 'COMMITTING',
44
-
45
- /**
46
- * Transaction was sent to the server for comitting but was failed.
47
- */
48
- COMMIT_FAILED: 'COMMIT_FAILED',
49
-
50
- /**
51
- * Transaction has been rolled back by the developer.
52
- */
53
- ROLLED_BACK: 'ROLLED_BACK'
54
- };
55
- module.exports = RelayMutationTransactionStatus;
@@ -1,131 +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 RelayNetworkDebugger =
13
- /*#__PURE__*/
14
- function () {
15
- function RelayNetworkDebugger(environment, graphiqlPrinter) {
16
- var _this = this;
17
-
18
- this._initTime = require("fbjs/lib/performanceNow")();
19
- this._queryID = 0;
20
- this._subscription = environment.addNetworkSubscriber(function (request) {
21
- return _this.logRequest(createDebuggableFromRequest('Relay Query', request, graphiqlPrinter));
22
- }, function (request) {
23
- return _this.logRequest(createDebuggableFromRequest('Relay Mutation', request, graphiqlPrinter));
24
- });
25
- }
26
-
27
- var _proto = RelayNetworkDebugger.prototype;
28
-
29
- _proto.uninstall = function uninstall() {
30
- this._subscription.remove();
31
- };
32
-
33
- _proto.logRequest = function logRequest(_ref) {
34
- var _this2 = this;
35
-
36
- var name = _ref.name,
37
- type = _ref.type,
38
- promise = _ref.promise,
39
- logResult = _ref.logResult;
40
- var id = this._queryID++;
41
- var timerName = "[".concat(id, "] Request Duration");
42
- console.timeStamp && console.timeStamp("START: [".concat(id, "] ").concat(type, ": ").concat(name, " \u2192"));
43
- console.time && console.time(timerName);
44
-
45
- var onSettled = function onSettled(error, response) {
46
- var time = (require("fbjs/lib/performanceNow")() - _this2._initTime) / 1000;
47
- console.timeStamp && console.timeStamp("\u2190 END: [".concat(id, "] ").concat(type, ": ").concat(name));
48
- var groupName = "%c[".concat(id, "] ").concat(type, ": ").concat(name, " @ ").concat(time, "s");
49
- console.groupCollapsed(groupName, "color:".concat(error ? 'red' : 'black', ";"));
50
- console.timeEnd && console.timeEnd(timerName);
51
- logResult(error, response);
52
- console.groupEnd();
53
- };
54
-
55
- promise.then(function (response) {
56
- return onSettled(null, response);
57
- }, function (error) {
58
- return onSettled(error, null);
59
- });
60
- };
61
-
62
- return RelayNetworkDebugger;
63
- }();
64
-
65
- function createDebuggableFromRequest(type, request, graphiqlPrinter) {
66
- return {
67
- name: request.getDebugName(),
68
- type: type,
69
- promise: request.getPromise(),
70
- logResult: function logResult(error, response) {
71
- var requestSize = formatSize(require("fbjs/lib/xhrSimpleDataSerializer")({
72
- q: request.getQueryString(),
73
- query_params: request.getVariables()
74
- }).length);
75
- var requestVariables = request.getVariables();
76
- console.groupCollapsed('Request Query (Estimated Size: %s)', requestSize);
77
-
78
- if (graphiqlPrinter) {
79
- console.groupCollapsed('GraphiQL Link');
80
- console.debug(graphiqlPrinter(request));
81
- console.groupEnd();
82
- }
83
-
84
- console.groupCollapsed('Query Text');
85
- console.debug('%c%s\n', 'font-size:10px; color:#333; font-family:mplus-2m-regular,menlo,' + 'monospaced;', request.getQueryString());
86
- console.groupEnd();
87
- console.groupEnd();
88
-
89
- if (Object.keys(requestVariables).length > 0) {
90
- // eslint-disable-next-line no-console
91
- console.log('Request Variables\n', request.getVariables());
92
- }
93
-
94
- error && console.error(error); // eslint-disable-next-line no-console
95
-
96
- response && console.log(response);
97
- }
98
- };
99
- }
100
-
101
- var ALL_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
102
-
103
- function formatSize(bytes) {
104
- var sign = bytes < 0 ? -1 : 1;
105
- bytes = Math.abs(bytes);
106
- var i = 0;
107
-
108
- while (bytes >= Math.pow(1024, i + 1) && i < ALL_UNITS.length) {
109
- i++;
110
- }
111
-
112
- var value = sign * bytes * 1.0 / Math.pow(1024, i);
113
- return Number(value.toFixed(2)) + ALL_UNITS[i];
114
- }
115
-
116
- var networkDebugger;
117
- var RelayNetworkDebug = {
118
- init: function init() {
119
- var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : require("./RelayPublic").Store;
120
- var graphiqlPrinter = arguments.length > 1 ? arguments[1] : undefined;
121
- networkDebugger && networkDebugger.uninstall(); // Without `groupCollapsed`, RelayNetworkDebug is too noisy.
122
-
123
- if (console.groupCollapsed) {
124
- networkDebugger = new RelayNetworkDebugger(environment, graphiqlPrinter);
125
- }
126
- },
127
- logRequest: function logRequest(request) {
128
- networkDebugger && networkDebugger.logRequest(request);
129
- }
130
- };
131
- module.exports = RelayNetworkDebug;
@@ -1,185 +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
- * `RelayNetworkLayer` provides a method to inject custom network behavior.
16
- */
17
- var RelayNetworkLayer =
18
- /*#__PURE__*/
19
- function () {
20
- function RelayNetworkLayer() {
21
- this._implementation = null;
22
- this._queue = null;
23
- this._subscribers = [];
24
- }
25
- /**
26
- * @internal
27
- */
28
-
29
-
30
- var _proto = RelayNetworkLayer.prototype;
31
-
32
- _proto.injectDefaultImplementation = function injectDefaultImplementation(implementation) {
33
- if (this._defaultImplementation) {
34
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayNetworkLayer: Call received to injectDefaultImplementation(), ' + 'but a default layer was already injected.') : void 0;
35
- }
36
-
37
- this._defaultImplementation = implementation;
38
- };
39
-
40
- _proto.injectImplementation = function injectImplementation(implementation) {
41
- if (this._implementation) {
42
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayNetworkLayer: Call received to injectImplementation(), but ' + 'a layer was already injected.') : void 0;
43
- }
44
-
45
- this._implementation = implementation;
46
- };
47
-
48
- _proto.addNetworkSubscriber = function addNetworkSubscriber(queryCallback, mutationCallback) {
49
- var _this = this;
50
-
51
- var index = this._subscribers.length;
52
-
53
- this._subscribers.push({
54
- queryCallback: queryCallback,
55
- mutationCallback: mutationCallback
56
- });
57
-
58
- return {
59
- remove: function remove() {
60
- delete _this._subscribers[index];
61
- }
62
- };
63
- };
64
-
65
- _proto.sendMutation = function sendMutation(mutationRequest) {
66
- var implementation = this._getImplementation();
67
-
68
- this._subscribers.forEach(function (_ref) {
69
- var mutationCallback = _ref.mutationCallback;
70
-
71
- if (mutationCallback) {
72
- mutationCallback(mutationRequest);
73
- }
74
- });
75
-
76
- var maybePromise = implementation.sendMutation(mutationRequest);
77
-
78
- if (maybePromise) {
79
- require("./throwFailedPromise")(Promise.resolve(maybePromise));
80
- }
81
- };
82
-
83
- _proto.sendQueries = function sendQueries(queryRequests) {
84
- profileQueue(queryRequests);
85
-
86
- var implementation = this._getImplementation();
87
-
88
- this._subscribers.forEach(function (_ref2) {
89
- var queryCallback = _ref2.queryCallback;
90
-
91
- if (queryCallback) {
92
- queryRequests.forEach(function (request) {
93
- queryCallback(request);
94
- });
95
- }
96
- });
97
-
98
- var maybePromise = implementation.sendQueries(queryRequests);
99
-
100
- if (maybePromise) {
101
- require("./throwFailedPromise")(Promise.resolve(maybePromise));
102
- }
103
- };
104
-
105
- _proto.supports = function supports() {
106
- var implementation = this._getImplementation();
107
-
108
- for (var _len = arguments.length, options = new Array(_len), _key = 0; _key < _len; _key++) {
109
- options[_key] = arguments[_key];
110
- }
111
-
112
- return implementation.supports.apply(implementation, options);
113
- };
114
-
115
- _proto._getImplementation = function _getImplementation() {
116
- var implementation = this._implementation || this._defaultImplementation;
117
- !implementation ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayNetworkLayer: Use `RelayEnvironment.injectNetworkLayer` to ' + 'configure a network layer.') : require("fbjs/lib/invariant")(false) : void 0;
118
- return implementation;
119
- };
120
- /**
121
- * Schedules the supplied `query` to be sent to the server.
122
- *
123
- * This is a low-level transport API; application code should use higher-level
124
- * interfaces exposed by RelayContainer for retrieving data transparently via
125
- * queries defined on components.
126
- */
127
-
128
-
129
- _proto.fetchRelayQuery = function fetchRelayQuery(query) {
130
- var _this2 = this;
131
-
132
- var currentQueue = this._queue || [];
133
-
134
- if (!this._queue) {
135
- this._queue = currentQueue;
136
-
137
- require("fbjs/lib/resolveImmediate")(function () {
138
- _this2._queue = null;
139
-
140
- _this2.sendQueries(currentQueue);
141
- });
142
- }
143
-
144
- var request = new (require("./RelayQueryRequest"))(query);
145
- currentQueue.push(request);
146
- return request.getPromise();
147
- };
148
-
149
- return RelayNetworkLayer;
150
- }();
151
- /**
152
- * Profiles time from request to receiving the first server response.
153
- */
154
-
155
-
156
- function profileQueue(currentQueue) {
157
- // TODO #8783781: remove aggregate `fetchRelayQuery` profiler
158
- var firstResultProfiler = require("relay-runtime").RelayProfiler.profile('fetchRelayQuery');
159
-
160
- currentQueue.forEach(function (query) {
161
- var profiler = require("relay-runtime").RelayProfiler.profile('fetchRelayQuery.query', query.getQuery().getName());
162
-
163
- var onSettle = function onSettle() {
164
- profiler.stop();
165
-
166
- if (firstResultProfiler) {
167
- firstResultProfiler.stop();
168
- firstResultProfiler = null;
169
- }
170
- };
171
-
172
- query.getPromise().then(onSettle, onSettle)["catch"](function (error) {
173
- setTimeout(function () {
174
- throw error;
175
- }, 0);
176
- });
177
- });
178
- }
179
-
180
- require("relay-runtime").RelayProfiler.instrumentMethods(RelayNetworkLayer.prototype, {
181
- sendMutation: 'RelayNetworkLayer.sendMutation',
182
- sendQueries: 'RelayNetworkLayer.sendQueries'
183
- });
184
-
185
- module.exports = RelayNetworkLayer;
@@ -1,104 +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 getResultsFromPayloadImpl = getResultsFromPayload;
13
- /**
14
- * @internal
15
- *
16
- * Defines logic relevant to the informal "Node" GraphQL interface.
17
- */
18
-
19
- var RelayNodeInterface = {
20
- ANY_TYPE: '__any',
21
- ID: 'id',
22
- ID_TYPE: 'ID!',
23
- NODE: 'node',
24
- NODE_TYPE: 'Node',
25
- NODES: 'nodes',
26
- TYPENAME: '__typename',
27
- isNodeRootCall: function isNodeRootCall(fieldName) {
28
- return fieldName === RelayNodeInterface.NODE || fieldName === RelayNodeInterface.NODES;
29
- },
30
- getResultsFromPayload: function getResultsFromPayload(query, payload) {
31
- return getResultsFromPayloadImpl(query, payload);
32
- },
33
-
34
- /**
35
- * Allow for injecting custom behavior for getResultsFromPayload.
36
- */
37
- injectGetResultsFromPayloadImpl: function injectGetResultsFromPayloadImpl(impl) {
38
- getResultsFromPayloadImpl = impl;
39
- }
40
- };
41
-
42
- function getResultsFromPayload(query, payload) {
43
- var results = [];
44
- var rootBatchCall = query.getBatchCall();
45
-
46
- if (rootBatchCall) {
47
- getPayloadRecords(query, payload).forEach(function (result) {
48
- if (typeof result !== 'object' || !result) {
49
- return;
50
- }
51
-
52
- var dataID = result[RelayNodeInterface.ID];
53
- !(typeof dataID === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayNodeInterface.getResultsFromPayload(): Unable to write ' + 'result with no `%s` field for query, `%s`.', RelayNodeInterface.ID, query.getName()) : require("fbjs/lib/invariant")(false) : void 0;
54
- results.push({
55
- result: result,
56
- rootCallInfo: {
57
- storageKey: RelayNodeInterface.NODE,
58
- identifyingArgKey: dataID,
59
- identifyingArgValue: dataID
60
- }
61
- });
62
- });
63
- } else {
64
- var records = getPayloadRecords(query, payload);
65
- var ii = 0;
66
- var storageKey = query.getStorageKey();
67
-
68
- require("./forEachRootCallArg")(query, function (_ref) {
69
- var identifyingArgKey = _ref.identifyingArgKey,
70
- identifyingArgValue = _ref.identifyingArgValue;
71
- var result = records[ii++];
72
- results.push({
73
- result: result,
74
- rootCallInfo: {
75
- storageKey: storageKey,
76
- identifyingArgKey: identifyingArgKey,
77
- identifyingArgValue: identifyingArgValue
78
- }
79
- });
80
- });
81
- }
82
-
83
- return results;
84
- }
85
-
86
- function getPayloadRecords(query, payload) {
87
- var fieldName = query.getFieldName();
88
- var identifyingArg = query.getIdentifyingArg();
89
- var identifyingArgValue = identifyingArg && identifyingArg.value || null;
90
- var records = payload[fieldName];
91
-
92
- if (!query.getBatchCall()) {
93
- if (Array.isArray(identifyingArgValue)) {
94
- !Array.isArray(records) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayNodeInterface: Expected payload for root field `%s` to be ' + 'an array with %s results, instead received a single non-array result.', fieldName, identifyingArgValue.length) : require("fbjs/lib/invariant")(false) : void 0;
95
- !(records.length === identifyingArgValue.length) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayNodeInterface: Expected payload for root field `%s` to be ' + 'an array with %s results, instead received an array with %s results.', fieldName, identifyingArgValue.length, records.length) : require("fbjs/lib/invariant")(false) : void 0;
96
- } else if (Array.isArray(records)) {
97
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayNodeInterface: Expected payload for root field `%s` to be ' + 'a single non-array result, instead received an array with %s results.', fieldName, records.length) : require("fbjs/lib/invariant")(false) : void 0;
98
- }
99
- }
100
-
101
- return Array.isArray(records) ? records : [records || null];
102
- }
103
-
104
- module.exports = RelayNodeInterface;