relay-runtime 1.3.0 → 1.5.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 (90) hide show
  1. package/LICENSE +16 -26
  2. package/index.js +3 -6
  3. package/lib/ConvertToExecuteFunction.js +73 -0
  4. package/lib/RelayConcreteNode.js +31 -14
  5. package/lib/RelayConcreteVariables.js +11 -6
  6. package/lib/RelayConnectionHandler.js +2 -4
  7. package/lib/RelayConnectionInterface.js +3 -5
  8. package/lib/RelayCore.js +4 -6
  9. package/lib/RelayDataLoader.js +2 -4
  10. package/lib/RelayDeclarativeMutationConfig.js +316 -0
  11. package/lib/RelayDefaultHandleKey.js +2 -4
  12. package/lib/RelayDefaultHandlerProvider.js +2 -4
  13. package/lib/RelayError.js +2 -6
  14. package/lib/RelayInMemoryRecordSource.js +2 -4
  15. package/lib/RelayInternalTypes.js +2 -5
  16. package/lib/RelayInternals.js +2 -5
  17. package/lib/RelayMarkSweepStore.js +22 -5
  18. package/lib/RelayMetricsRecorder.js +9 -9
  19. package/lib/RelayMockRenderer.js +3 -8
  20. package/lib/RelayModernEnvironment.js +120 -135
  21. package/lib/RelayModernFragmentSpecResolver.js +81 -55
  22. package/lib/RelayModernGraphQLTag.js +8 -17
  23. package/lib/RelayModernOperationSelector.js +8 -8
  24. package/lib/RelayModernRecord.js +8 -8
  25. package/lib/RelayModernSelector.js +54 -43
  26. package/lib/RelayNetwork.js +9 -11
  27. package/lib/RelayNetworkDebug.js +4 -7
  28. package/lib/RelayNetworkLogger.js +2 -4
  29. package/lib/RelayNetworkLoggerTransaction.js +18 -20
  30. package/lib/RelayNetworkTypes.js +2 -4
  31. package/lib/RelayObservable.js +193 -120
  32. package/lib/RelayProfiler.js +7 -7
  33. package/lib/RelayPublishQueue.js +17 -9
  34. package/lib/RelayQueryCaching.js +2 -5
  35. package/lib/RelayQueryResponseCache.js +3 -5
  36. package/lib/RelayReader.js +18 -8
  37. package/lib/RelayRecordProxy.js +12 -11
  38. package/lib/RelayRecordSourceMutator.js +9 -9
  39. package/lib/RelayRecordSourceProxy.js +15 -13
  40. package/lib/RelayRecordSourceSelectorProxy.js +2 -4
  41. package/lib/RelayRecordState.js +2 -4
  42. package/lib/RelayReferenceMarker.js +2 -4
  43. package/lib/RelayResponseNormalizer.js +34 -25
  44. package/lib/RelayRuntime.js +25 -14
  45. package/lib/RelayRuntimeTypes.js +22 -0
  46. package/lib/RelayShallowMock.js +4 -7
  47. package/lib/RelayStoreTypes.js +2 -4
  48. package/lib/RelayStoreUtils.js +66 -26
  49. package/lib/RelayTaskQueue.js +2 -5
  50. package/lib/RelayTypes.js +2 -5
  51. package/lib/RelayViewerHandler.js +4 -5
  52. package/lib/applyRelayModernOptimisticMutation.js +9 -8
  53. package/lib/cloneRelayHandleSourceField.js +4 -11
  54. package/lib/commitLocalUpdate.js +2 -4
  55. package/lib/commitRelayModernMutation.js +24 -22
  56. package/lib/createRelayNetworkLogger.js +25 -27
  57. package/lib/dedent.js +2 -5
  58. package/lib/deepFreeze.js +3 -5
  59. package/lib/deferrableFragmentKey.js +21 -0
  60. package/lib/fetchRelayModernQuery.js +13 -21
  61. package/lib/generateRelayClientID.js +2 -4
  62. package/lib/getRelayHandleKey.js +2 -4
  63. package/lib/hasOverlappingIDs.js +2 -4
  64. package/lib/isCompatibleRelayFragmentType.js +2 -5
  65. package/lib/isPromise.js +2 -5
  66. package/lib/isRelayModernEnvironment.js +2 -4
  67. package/lib/isScalarAndEqual.js +3 -5
  68. package/lib/normalizePayload.js +10 -13
  69. package/lib/normalizeRelayPayload.js +8 -5
  70. package/lib/recycleNodesInto.js +2 -4
  71. package/lib/relayUnstableBatchedUpdates.js +2 -5
  72. package/lib/relayUnstableBatchedUpdates.native.js +2 -5
  73. package/lib/requestRelaySubscription.js +20 -34
  74. package/lib/simpleClone.js +2 -4
  75. package/lib/stableCopy.js +35 -0
  76. package/lib/testEditDistance.js +2 -5
  77. package/lib/throwFailedPromise.js +2 -5
  78. package/package.json +4 -5
  79. package/relay-runtime.js +2307 -2665
  80. package/relay-runtime.min.js +6 -9
  81. package/ARCHITECTURE.md +0 -232
  82. package/PATENTS +0 -33
  83. package/lib/ConvertToObserveFunction.js +0 -39
  84. package/lib/RelayDebugger.js +0 -199
  85. package/lib/RelayRecordSourceInspector.js +0 -289
  86. package/lib/RelayStoreProxyDebugger.js +0 -44
  87. package/lib/formatStorageKey.js +0 -37
  88. package/lib/prettyStringify.js +0 -35
  89. package/lib/setRelayModernMutationConfigs.js +0 -302
  90. package/lib/stableJSONStringify.js +0 -45
package/lib/isPromise.js CHANGED
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule isPromise
10
8
  *
@@ -13,7 +11,6 @@
13
11
 
14
12
  'use strict';
15
13
 
16
- // eslint-disable-next-line no-redeclare
17
14
  function isPromise(p) {
18
15
  return !!p && typeof p.then === 'function';
19
16
  }
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule isRelayModernEnvironment
10
8
  *
@@ -1,13 +1,11 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
- *
10
7
  * @providesModule isScalarAndEqual
8
+ *
11
9
  * @format
12
10
  */
13
11
 
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule normalizePayload
10
8
  *
@@ -13,22 +11,21 @@
13
11
 
14
12
  'use strict';
15
13
 
16
- var _extends3 = _interopRequireDefault(require('babel-runtime/helpers/extends'));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
19
-
20
14
  var _require = require('./RelayStoreUtils'),
21
15
  ROOT_ID = _require.ROOT_ID;
22
16
 
23
- function normalizePayload(operation, variables, payload) {
24
- var data = payload.data,
25
- errors = payload.errors;
17
+ function normalizePayload(payload) {
18
+ var operation = payload.operation,
19
+ variables = payload.variables,
20
+ response = payload.response;
21
+ var data = response.data,
22
+ errors = response.errors;
26
23
 
27
24
  if (data != null) {
28
25
  return require('./normalizeRelayPayload')({
29
26
  dataID: ROOT_ID,
30
- node: operation.query,
31
- variables: payload.rerunVariables ? (0, _extends3['default'])({}, variables, payload.rerunVariables) : variables
27
+ node: operation,
28
+ variables: variables
32
29
  }, data, errors, { handleStrippedNulls: true });
33
30
  }
34
31
  var error = require('./RelayError').create('RelayNetwork', 'No data returned for operation `%s`, got error(s):\n%s\n\nSee the error ' + '`source` property for more information.', operation.name, errors ? errors.map(function (_ref) {
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule normalizeRelayPayload
10
8
  *
@@ -22,10 +20,15 @@ function normalizeRelayPayload(selector, payload, errors) {
22
20
 
23
21
  var source = new (require('./RelayInMemoryRecordSource'))();
24
22
  source.set(ROOT_ID, require('./RelayModernRecord').create(ROOT_ID, ROOT_TYPE));
25
- var fieldPayloads = require('./RelayResponseNormalizer').normalize(source, selector, payload, options);
23
+
24
+ var _RelayResponseNormali = require('./RelayResponseNormalizer').normalize(source, selector, payload, options),
25
+ fieldPayloads = _RelayResponseNormali.fieldPayloads,
26
+ deferrableSelections = _RelayResponseNormali.deferrableSelections;
27
+
26
28
  return {
27
29
  errors: errors,
28
30
  fieldPayloads: fieldPayloads,
31
+ deferrableSelections: deferrableSelections,
29
32
  source: source
30
33
  };
31
34
  }
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule recycleNodesInto
10
8
  *
@@ -1,12 +1,9 @@
1
1
  /**
2
2
  * Copyright 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
- * @providesModule relayUnstableBatchedUpdates
10
7
  *
11
8
  * @format
12
9
  */
@@ -1,12 +1,9 @@
1
1
  /**
2
2
  * Copyright 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
- * @providesModule relayUnstableBatchedUpdates
10
7
  * @format
11
8
  */
12
9
 
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule requestRelaySubscription
10
8
  *
@@ -16,48 +14,36 @@
16
14
  function requestRelaySubscription(environment, config) {
17
15
  var _environment$unstable = environment.unstable_internal,
18
16
  createOperationSelector = _environment$unstable.createOperationSelector,
19
- getOperation = _environment$unstable.getOperation;
17
+ getRequest = _environment$unstable.getRequest;
20
18
 
21
- var subscription = getOperation(config.subscription);
19
+ var subscription = getRequest(config.subscription);
20
+ if (subscription.operationKind !== 'subscription') {
21
+ throw new Error('requestRelaySubscription: Must use Subscription operation');
22
+ }
22
23
  var configs = config.configs,
23
24
  onCompleted = config.onCompleted,
24
25
  onError = config.onError,
25
26
  onNext = config.onNext,
26
27
  variables = config.variables;
27
- var updater = config.updater;
28
28
 
29
29
  var operation = createOperationSelector(subscription, variables);
30
30
 
31
- require('fbjs/lib/warning')(!(updater && configs), 'requestRelaySubscription: Expected only one of `updater` and `configs` to be provided');
32
-
33
- if (configs) {
34
- var _setRelayModernMutati = require('./setRelayModernMutationConfigs')(configs, subscription, null /* optimisticUpdater */
35
- , updater);
31
+ require('fbjs/lib/warning')(!(config.updater && configs), 'requestRelaySubscription: Expected only one of `updater` and `configs` to be provided');
36
32
 
37
- updater = _setRelayModernMutati.updater;
38
- }
39
- return environment.sendSubscription({
40
- onCompleted: onCompleted,
41
- onError: onError,
42
- onNext: function (_onNext) {
43
- function onNext(_x) {
44
- return _onNext.apply(this, arguments);
45
- }
46
-
47
- onNext.toString = function () {
48
- return _onNext.toString();
49
- };
50
-
51
- return onNext;
52
- }(function (payload) {
53
- if (onNext) {
54
- var snapshot = environment.lookup(operation.fragment);
55
- onNext(snapshot.data);
56
- }
57
- }),
33
+ var _ref = configs ? require('./RelayDeclarativeMutationConfig').convert(configs, subscription, null /* optimisticUpdater */
34
+ , config.updater) : config,
35
+ updater = _ref.updater;
58
36
 
37
+ return environment.execute({
38
+ operation: operation,
59
39
  updater: updater,
60
- operation: operation
40
+ cacheConfig: { force: true }
41
+ }).map(function () {
42
+ return environment.lookup(operation.fragment).data;
43
+ }).subscribeLegacy({
44
+ onNext: onNext,
45
+ onError: onError,
46
+ onCompleted: onCompleted
61
47
  });
62
48
  }
63
49
 
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule simpleClone
10
8
  *
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
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
+ * @providesModule stableCopy
8
+ *
9
+ * @format
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ /**
15
+ * Creates a copy of the provided value, ensuring any nested objects have their
16
+ * keys sorted such that equivalent values would have identical JSON.stringify
17
+ * results.
18
+ */
19
+
20
+ function stableCopy(value) {
21
+ if (!value || typeof value !== 'object') {
22
+ return value;
23
+ }
24
+ if (Array.isArray(value)) {
25
+ return value.map(stableCopy);
26
+ }
27
+ var keys = Object.keys(value).sort();
28
+ var stable = {};
29
+ for (var i = 0; i < keys.length; i++) {
30
+ stable[keys[i]] = stableCopy(value[keys[i]]);
31
+ }
32
+ return stable;
33
+ }
34
+
35
+ module.exports = stableCopy;
@@ -1,12 +1,9 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
- * @providesModule testEditDistance
10
7
  *
11
8
  * @format
12
9
  *
@@ -1,13 +1,10 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  *
10
- * @providesModule throwFailedPromise
11
8
  * @format
12
9
  */
13
10
 
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "relay-runtime",
3
3
  "description": "A core runtime for building GraphQL-driven applications.",
4
- "version": "1.3.0",
4
+ "version": "1.5.0",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"
8
8
  ],
9
- "license": "BSD-3-Clause",
9
+ "license": "MIT",
10
10
  "homepage": "https://facebook.github.io/relay/",
11
11
  "bugs": "https://github.com/facebook/relay/issues",
12
12
  "repository": "facebook/relay",
13
13
  "dependencies": {
14
14
  "babel-runtime": "^6.23.0",
15
- "fbjs": "^0.8.1",
16
- "relay-debugger-react-native-runtime": "^0.0.9"
15
+ "fbjs": "^0.8.14"
17
16
  },
18
17
  "peerDependencies": {
19
- "relay-compiler": "1.3.0"
18
+ "relay-compiler": "1.5.0"
20
19
  }
21
20
  }