relay-runtime 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 (77) hide show
  1. package/index.js +1 -1
  2. package/lib/{generateRelayClientID.js → ClientID.js} +10 -3
  3. package/lib/ConvertToExecuteFunction.js +6 -4
  4. package/lib/DataChecker.js +88 -69
  5. package/lib/NormalizationNode.js +1 -1
  6. package/lib/ReaderNode.js +1 -1
  7. package/lib/RelayCombinedEnvironmentTypes.js +1 -1
  8. package/lib/RelayConcreteNode.js +5 -2
  9. package/lib/RelayConcreteVariables.js +15 -9
  10. package/lib/RelayConnectionHandler.js +27 -20
  11. package/lib/RelayConnectionInterface.js +4 -2
  12. package/lib/RelayCore.js +48 -15
  13. package/lib/RelayDeclarativeMutationConfig.js +16 -15
  14. package/lib/RelayDefaultHandleKey.js +1 -1
  15. package/lib/RelayDefaultHandlerProvider.js +7 -6
  16. package/lib/RelayDefaultMissingFieldHandlers.js +26 -0
  17. package/lib/RelayError.js +7 -2
  18. package/lib/RelayFeatureFlags.js +16 -0
  19. package/lib/RelayInMemoryRecordSource.js +8 -2
  20. package/lib/RelayModernEnvironment.js +159 -237
  21. package/lib/RelayModernFragmentOwner.js +72 -0
  22. package/lib/RelayModernFragmentSpecResolver.js +66 -15
  23. package/lib/RelayModernGraphQLTag.js +9 -5
  24. package/lib/RelayModernOperationDescriptor.js +9 -6
  25. package/lib/RelayModernQueryExecutor.js +791 -0
  26. package/lib/RelayModernRecord.js +44 -24
  27. package/lib/RelayModernSelector.js +208 -82
  28. package/lib/RelayModernStore.js +66 -34
  29. package/lib/RelayNetwork.js +14 -7
  30. package/lib/RelayNetworkLogger.js +6 -2
  31. package/lib/RelayNetworkLoggerTransaction.js +8 -4
  32. package/lib/RelayNetworkTypes.js +1 -1
  33. package/lib/RelayObservable.js +72 -41
  34. package/lib/RelayOperationTracker.js +265 -0
  35. package/lib/RelayProfiler.js +10 -6
  36. package/lib/RelayPublishQueue.js +66 -47
  37. package/lib/RelayQueryResponseCache.js +11 -5
  38. package/lib/RelayReader.js +135 -126
  39. package/lib/RelayRecordProxy.js +24 -20
  40. package/lib/RelayRecordSourceMutator.js +88 -25
  41. package/lib/RelayRecordSourceProxy.js +38 -19
  42. package/lib/RelayRecordSourceSelectorProxy.js +10 -7
  43. package/lib/RelayRecordState.js +1 -1
  44. package/lib/RelayReferenceMarker.js +66 -55
  45. package/lib/RelayReplaySubject.js +134 -0
  46. package/lib/RelayResponseNormalizer.js +245 -134
  47. package/lib/RelayRuntimeTypes.js +1 -1
  48. package/lib/RelayStoreUtils.js +55 -16
  49. package/lib/RelayViewerHandler.js +8 -50
  50. package/lib/StoreInspector.js +171 -0
  51. package/lib/applyRelayModernOptimisticMutation.js +8 -2
  52. package/lib/cloneRelayHandleSourceField.js +17 -7
  53. package/lib/commitLocalUpdate.js +1 -1
  54. package/lib/commitRelayModernMutation.js +33 -13
  55. package/lib/createRelayContext.js +27 -0
  56. package/lib/createRelayNetworkLogger.js +8 -2
  57. package/lib/deepFreeze.js +1 -1
  58. package/lib/defaultGetDataID.js +24 -0
  59. package/lib/fetchQueryInternal.js +232 -0
  60. package/lib/fetchRelayModernQuery.js +5 -3
  61. package/lib/getFragmentIdentifier.js +52 -0
  62. package/lib/getFragmentSpecIdentifier.js +26 -0
  63. package/lib/getRelayHandleKey.js +8 -2
  64. package/lib/getRequestParametersIdentifier.js +26 -0
  65. package/lib/hasOverlappingIDs.js +1 -1
  66. package/lib/index.js +155 -53
  67. package/lib/isPromise.js +1 -1
  68. package/lib/isScalarAndEqual.js +1 -1
  69. package/lib/normalizeRelayPayload.js +19 -10
  70. package/lib/recycleNodesInto.js +23 -5
  71. package/lib/requestRelaySubscription.js +9 -3
  72. package/lib/validateMutation.js +13 -6
  73. package/package.json +2 -2
  74. package/relay-runtime.js +2 -2
  75. package/relay-runtime.min.js +2 -2
  76. package/lib/normalizePayload.js +0 -37
  77. package/lib/simpleClone.js +0 -27
@@ -4,26 +4,35 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * strict-local
7
+ *
8
8
  * @format
9
9
  */
10
10
  'use strict';
11
11
 
12
- function normalizeRelayPayload(selector, payload, errors) {
13
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
14
- handleStrippedNulls: false
15
- };
16
- var source = new (require("./RelayInMemoryRecordSource"))();
17
- source.set(require("./RelayStoreUtils").ROOT_ID, require("./RelayModernRecord").create(require("./RelayStoreUtils").ROOT_ID, require("./RelayStoreUtils").ROOT_TYPE));
12
+ var RelayInMemoryRecordSource = require("./RelayInMemoryRecordSource");
13
+
14
+ var RelayModernRecord = require("./RelayModernRecord");
15
+
16
+ var RelayResponseNormalizer = require("./RelayResponseNormalizer");
17
+
18
+ var _require = require("./RelayStoreUtils"),
19
+ ROOT_ID = _require.ROOT_ID,
20
+ ROOT_TYPE = _require.ROOT_TYPE;
21
+
22
+ function normalizeRelayPayload(selector, payload, errors, options) {
23
+ var source = new RelayInMemoryRecordSource();
24
+ source.set(ROOT_ID, RelayModernRecord.create(ROOT_ID, ROOT_TYPE));
18
25
 
19
- var _RelayResponseNormali = require("./RelayResponseNormalizer").normalize(source, selector, payload, options),
26
+ var _RelayResponseNormali = RelayResponseNormalizer.normalize(source, selector, payload, options),
20
27
  fieldPayloads = _RelayResponseNormali.fieldPayloads,
21
- matchPayloads = _RelayResponseNormali.matchPayloads;
28
+ incrementalPlaceholders = _RelayResponseNormali.incrementalPlaceholders,
29
+ moduleImportPayloads = _RelayResponseNormali.moduleImportPayloads;
22
30
 
23
31
  return {
24
32
  errors: errors,
25
33
  fieldPayloads: fieldPayloads,
26
- matchPayloads: matchPayloads,
34
+ incrementalPlaceholders: incrementalPlaceholders,
35
+ moduleImportPayloads: moduleImportPayloads,
27
36
  source: source
28
37
  };
29
38
  }
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * strict
7
+ *
8
8
  * @format
9
9
  */
10
10
  'use strict';
@@ -28,10 +28,16 @@ function recycleNodesInto(prevData, nextData) {
28
28
  var nextValue = recycleNodesInto(prevValue, nextItem);
29
29
 
30
30
  if (nextValue !== nextArray[ii]) {
31
- nextArray[ii] = nextValue;
31
+ if (process.env.NODE_ENV !== "production") {
32
+ if (!Object.isFrozen(nextArray)) {
33
+ nextArray[ii] = nextValue;
34
+ }
35
+ } else {
36
+ nextArray[ii] = nextValue;
37
+ }
32
38
  }
33
39
 
34
- return wasEqual && nextArray[ii] === prevArray[ii];
40
+ return wasEqual && nextValue === prevArray[ii];
35
41
  }, true) && prevArray.length === nextArray.length;
36
42
  } else if (!prevArray && !nextArray) {
37
43
  // Assign local variables to preserve Flow type refinement.
@@ -44,10 +50,22 @@ function recycleNodesInto(prevData, nextData) {
44
50
  var nextValue = recycleNodesInto(prevValue, nextObject[key]);
45
51
 
46
52
  if (nextValue !== nextObject[key]) {
47
- nextObject[key] = nextValue;
53
+ if (process.env.NODE_ENV !== "production") {
54
+ if (!Object.isFrozen(nextObject)) {
55
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This
56
+ * comment suppresses an error found when Flow v0.98 was deployed.
57
+ * To see the error delete this comment and run Flow. */
58
+ nextObject[key] = nextValue;
59
+ }
60
+ } else {
61
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
62
+ * suppresses an error found when Flow v0.98 was deployed. To see
63
+ * the error delete this comment and run Flow. */
64
+ nextObject[key] = nextValue;
65
+ }
48
66
  }
49
67
 
50
- return wasEqual && nextObject[key] === prevObject[key];
68
+ return wasEqual && nextValue === prevObject[key];
51
69
  }, true) && prevKeys.length === nextKeys.length;
52
70
  }
53
71
 
@@ -9,6 +9,10 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
+ var RelayDeclarativeMutationConfig = require("./RelayDeclarativeMutationConfig");
13
+
14
+ var warning = require("fbjs/lib/warning");
15
+
12
16
  function requestRelaySubscription(environment, config) {
13
17
  var _environment$unstable = environment.unstable_internal,
14
18
  createOperationDescriptor = _environment$unstable.createOperationDescriptor,
@@ -25,9 +29,9 @@ function requestRelaySubscription(environment, config) {
25
29
  onNext = config.onNext,
26
30
  variables = config.variables;
27
31
  var operation = createOperationDescriptor(subscription, variables);
28
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(!(config.updater && configs), 'requestRelaySubscription: Expected only one of `updater` and `configs` to be provided') : void 0;
32
+ process.env.NODE_ENV !== "production" ? warning(!(config.updater && configs), 'requestRelaySubscription: Expected only one of `updater` and `configs` to be provided') : void 0;
29
33
 
30
- var _ref = configs ? require("./RelayDeclarativeMutationConfig").convert(configs, subscription, null
34
+ var _ref = configs ? RelayDeclarativeMutationConfig.convert(configs, subscription, null
31
35
  /* optimisticUpdater */
32
36
  , config.updater) : config,
33
37
  updater = _ref.updater;
@@ -39,7 +43,9 @@ function requestRelaySubscription(environment, config) {
39
43
  force: true
40
44
  }
41
45
  }).map(function () {
42
- return environment.lookup(operation.fragment).data;
46
+ var data = environment.lookup(operation.fragment, operation).data; // $FlowFixMe
47
+
48
+ return data;
43
49
  }).subscribeLegacy({
44
50
  onNext: onNext,
45
51
  onError: onError,
@@ -9,7 +9,11 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
- var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
12
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
13
+
14
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
15
+
16
+ var warning = require("fbjs/lib/warning");
13
17
 
14
18
  var validateMutation = function validateMutation() {};
15
19
 
@@ -43,7 +47,6 @@ if (process.env.NODE_ENV !== "production") {
43
47
 
44
48
  case 'ScalarField':
45
49
  case 'LinkedField':
46
- case 'MatchField':
47
50
  return validateField(optimisticResponse, selection, context);
48
51
 
49
52
  case 'InlineFragment':
@@ -57,8 +60,12 @@ if (process.env.NODE_ENV !== "production") {
57
60
  });
58
61
  return;
59
62
 
63
+ case 'ClientExtension':
64
+ case 'ModuleImport':
60
65
  case 'LinkedHandle':
61
66
  case 'ScalarHandle':
67
+ case 'Defer':
68
+ case 'Stream':
62
69
  {
63
70
  // TODO(T35864292) - Add missing validations for these types
64
71
  return;
@@ -78,7 +85,7 @@ if (process.env.NODE_ENV !== "production") {
78
85
  switch (field.kind) {
79
86
  case 'ScalarField':
80
87
  if (optimisticResponse[fieldName] === undefined) {
81
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'validateMutation: Expected `optimisticResponse` to match structure of server response for mutation `%s`, field %s is undefined', context.operationName, path) : void 0;
88
+ process.env.NODE_ENV !== "production" ? warning(false, 'validateMutation: Expected `optimisticResponse` to match structure of server response for mutation `%s`, field %s is undefined', context.operationName, path) : void 0;
82
89
  }
83
90
 
84
91
  return;
@@ -99,7 +106,7 @@ if (process.env.NODE_ENV !== "production") {
99
106
  });
100
107
  return;
101
108
  } else {
102
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'validateMutation: Expected `optimisticResponse` to match structure of server response for mutation `%s`, field %s is not an array', context.operationName, path) : void 0;
109
+ process.env.NODE_ENV !== "production" ? warning(false, 'validateMutation: Expected `optimisticResponse` to match structure of server response for mutation `%s`, field %s is not an array', context.operationName, path) : void 0;
103
110
  return;
104
111
  }
105
112
  } else {
@@ -109,7 +116,7 @@ if (process.env.NODE_ENV !== "production") {
109
116
  }));
110
117
  return;
111
118
  } else {
112
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'validateMutation: Expected `optimisticResponse` to match structure of server response for mutation `%s`, field %s is not an object', context.operationName, path) : void 0;
119
+ process.env.NODE_ENV !== "production" ? warning(false, 'validateMutation: Expected `optimisticResponse` to match structure of server response for mutation `%s`, field %s is not an object', context.operationName, path) : void 0;
113
120
  return;
114
121
  }
115
122
  }
@@ -130,7 +137,7 @@ if (process.env.NODE_ENV !== "production") {
130
137
  var path = "".concat(context.path, ".").concat(key);
131
138
 
132
139
  if (!context.visitedPaths.has(path)) {
133
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'validateMutation: `optimisticResponse` for mutation `%s`, contains an unused field %s', context.operationName, path) : void 0;
140
+ process.env.NODE_ENV !== "production" ? warning(false, 'validateMutation: `optimisticResponse` for mutation `%s`, contains an unused field %s', context.operationName, path) : void 0;
134
141
  return;
135
142
  }
136
143
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "relay-runtime",
3
3
  "description": "A core runtime for building GraphQL-driven applications.",
4
- "version": "2.0.0-rc.2",
4
+ "version": "5.0.0",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"
8
8
  ],
9
9
  "license": "MIT",
10
- "homepage": "https://facebook.github.io/relay/",
10
+ "homepage": "https://relay.dev",
11
11
  "bugs": "https://github.com/facebook/relay/issues",
12
12
  "repository": "facebook/relay",
13
13
  "dependencies": {