relay-runtime 8.0.0 → 10.0.1

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 (135) hide show
  1. package/handlers/RelayDefaultHandlerProvider.js.flow +41 -0
  2. package/handlers/connection/ConnectionHandler.js.flow +549 -0
  3. package/handlers/connection/ConnectionInterface.js.flow +92 -0
  4. package/handlers/connection/MutationHandlers.js.flow +88 -0
  5. package/index.js +1 -1
  6. package/index.js.flow +320 -0
  7. package/lib/handlers/RelayDefaultHandlerProvider.js +13 -2
  8. package/lib/handlers/connection/{RelayConnectionHandler.js → ConnectionHandler.js} +33 -35
  9. package/lib/handlers/connection/{RelayConnectionInterface.js → ConnectionInterface.js} +2 -2
  10. package/lib/handlers/connection/MutationHandlers.js +86 -0
  11. package/lib/index.js +15 -19
  12. package/lib/mutations/RelayDeclarativeMutationConfig.js +29 -52
  13. package/lib/mutations/RelayRecordProxy.js +1 -3
  14. package/lib/mutations/RelayRecordSourceMutator.js +2 -9
  15. package/lib/mutations/RelayRecordSourceProxy.js +2 -4
  16. package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -13
  17. package/lib/mutations/commitMutation.js +13 -3
  18. package/lib/mutations/validateMutation.js +16 -9
  19. package/lib/network/RelayObservable.js +9 -9
  20. package/lib/network/RelayQueryResponseCache.js +8 -6
  21. package/lib/query/PreloadableQueryRegistry.js +70 -0
  22. package/lib/query/fetchQueryInternal.js +31 -23
  23. package/lib/store/DataChecker.js +122 -110
  24. package/lib/store/RelayConcreteVariables.js +6 -2
  25. package/lib/store/RelayModernEnvironment.js +121 -67
  26. package/lib/store/RelayModernFragmentSpecResolver.js +12 -16
  27. package/lib/store/RelayModernQueryExecutor.js +389 -314
  28. package/lib/store/RelayModernRecord.js +14 -9
  29. package/lib/store/RelayModernSelector.js +7 -3
  30. package/lib/store/RelayModernStore.js +289 -484
  31. package/lib/store/RelayOperationTracker.js +35 -78
  32. package/lib/store/RelayOptimisticRecordSource.js +7 -5
  33. package/lib/store/RelayPublishQueue.js +6 -33
  34. package/lib/store/RelayReader.js +113 -45
  35. package/lib/store/RelayRecordSource.js +2 -9
  36. package/lib/store/RelayRecordSourceMapImpl.js +13 -18
  37. package/lib/store/RelayReferenceMarker.js +40 -60
  38. package/lib/store/RelayResponseNormalizer.js +158 -193
  39. package/lib/store/RelayStoreUtils.js +1 -0
  40. package/lib/store/StoreInspector.js +8 -8
  41. package/lib/store/TypeID.js +28 -0
  42. package/lib/store/cloneRelayScalarHandleSourceField.js +44 -0
  43. package/lib/store/normalizeRelayPayload.js +6 -2
  44. package/lib/store/readInlineData.js +1 -1
  45. package/lib/subscription/requestSubscription.js +5 -3
  46. package/lib/util/RelayConcreteNode.js +9 -6
  47. package/lib/util/RelayError.js +39 -9
  48. package/lib/util/RelayFeatureFlags.js +2 -5
  49. package/lib/util/RelayReplaySubject.js +3 -3
  50. package/lib/util/createPayloadFor3DField.js +7 -2
  51. package/lib/util/getRequestIdentifier.js +2 -2
  52. package/lib/util/recycleNodesInto.js +2 -6
  53. package/mutations/RelayDeclarativeMutationConfig.js.flow +380 -0
  54. package/mutations/RelayRecordProxy.js.flow +165 -0
  55. package/mutations/RelayRecordSourceMutator.js.flow +238 -0
  56. package/mutations/RelayRecordSourceProxy.js.flow +164 -0
  57. package/mutations/RelayRecordSourceSelectorProxy.js.flow +119 -0
  58. package/mutations/applyOptimisticMutation.js.flow +76 -0
  59. package/mutations/commitLocalUpdate.js.flow +24 -0
  60. package/mutations/commitMutation.js.flow +182 -0
  61. package/mutations/validateMutation.js.flow +213 -0
  62. package/network/ConvertToExecuteFunction.js.flow +49 -0
  63. package/network/RelayNetwork.js.flow +84 -0
  64. package/network/RelayNetworkTypes.js.flow +123 -0
  65. package/network/RelayObservable.js.flow +634 -0
  66. package/network/RelayQueryResponseCache.js.flow +111 -0
  67. package/package.json +1 -1
  68. package/query/GraphQLTag.js.flow +166 -0
  69. package/query/PreloadableQueryRegistry.js.flow +65 -0
  70. package/query/fetchQuery.js.flow +47 -0
  71. package/query/fetchQueryInternal.js.flow +348 -0
  72. package/relay-runtime.js +2 -2
  73. package/relay-runtime.min.js +2 -2
  74. package/store/ClientID.js.flow +43 -0
  75. package/store/DataChecker.js.flow +502 -0
  76. package/store/RelayConcreteVariables.js.flow +96 -0
  77. package/store/RelayModernEnvironment.js.flow +551 -0
  78. package/store/RelayModernFragmentSpecResolver.js.flow +426 -0
  79. package/store/RelayModernOperationDescriptor.js.flow +88 -0
  80. package/store/RelayModernQueryExecutor.js.flow +1321 -0
  81. package/store/RelayModernRecord.js.flow +403 -0
  82. package/store/RelayModernSelector.js.flow +455 -0
  83. package/store/RelayModernStore.js.flow +842 -0
  84. package/store/RelayOperationTracker.js.flow +164 -0
  85. package/store/RelayOptimisticRecordSource.js.flow +119 -0
  86. package/store/RelayPublishQueue.js.flow +401 -0
  87. package/store/RelayReader.js.flow +473 -0
  88. package/store/RelayRecordSource.js.flow +29 -0
  89. package/store/RelayRecordSourceMapImpl.js.flow +87 -0
  90. package/store/RelayRecordState.js.flow +37 -0
  91. package/store/RelayReferenceMarker.js.flow +257 -0
  92. package/store/RelayResponseNormalizer.js.flow +680 -0
  93. package/store/RelayStoreTypes.js.flow +899 -0
  94. package/store/RelayStoreUtils.js.flow +219 -0
  95. package/store/StoreInspector.js.flow +171 -0
  96. package/store/TypeID.js.flow +28 -0
  97. package/store/ViewerPattern.js.flow +26 -0
  98. package/store/cloneRelayHandleSourceField.js.flow +66 -0
  99. package/store/cloneRelayScalarHandleSourceField.js.flow +62 -0
  100. package/store/createFragmentSpecResolver.js.flow +55 -0
  101. package/store/createRelayContext.js.flow +44 -0
  102. package/store/defaultGetDataID.js.flow +27 -0
  103. package/store/hasOverlappingIDs.js.flow +34 -0
  104. package/store/isRelayModernEnvironment.js.flow +27 -0
  105. package/store/normalizeRelayPayload.js.flow +51 -0
  106. package/store/readInlineData.js.flow +75 -0
  107. package/subscription/requestSubscription.js.flow +100 -0
  108. package/util/JSResourceTypes.flow.js.flow +20 -0
  109. package/util/NormalizationNode.js.flow +198 -0
  110. package/util/ReaderNode.js.flow +208 -0
  111. package/util/RelayConcreteNode.js.flow +93 -0
  112. package/util/RelayDefaultHandleKey.js.flow +17 -0
  113. package/util/RelayError.js.flow +62 -0
  114. package/util/RelayFeatureFlags.js.flow +30 -0
  115. package/util/RelayProfiler.js.flow +284 -0
  116. package/util/RelayReplaySubject.js.flow +135 -0
  117. package/util/RelayRuntimeTypes.js.flow +72 -0
  118. package/util/createPayloadFor3DField.js.flow +43 -0
  119. package/util/deepFreeze.js.flow +36 -0
  120. package/util/generateID.js.flow +21 -0
  121. package/util/getFragmentIdentifier.js.flow +52 -0
  122. package/util/getRelayHandleKey.js.flow +41 -0
  123. package/util/getRequestIdentifier.js.flow +42 -0
  124. package/util/isPromise.js.flow +21 -0
  125. package/util/isScalarAndEqual.js.flow +26 -0
  126. package/util/recycleNodesInto.js.flow +76 -0
  127. package/util/resolveImmediate.js.flow +30 -0
  128. package/util/stableCopy.js.flow +35 -0
  129. package/lib/handlers/RelayDefaultMissingFieldHandlers.js +0 -26
  130. package/lib/handlers/getRelayDefaultMissingFieldHandlers.js +0 -36
  131. package/lib/query/RelayModernGraphQLTag.js +0 -104
  132. package/lib/store/RelayConnection.js +0 -37
  133. package/lib/store/RelayConnectionResolver.js +0 -178
  134. package/lib/store/RelayRecordSourceObjectImpl.js +0 -79
  135. package/lib/util/getFragmentSpecIdentifier.js +0 -27
@@ -0,0 +1,43 @@
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
+ * @emails oncall+relay
8
+ * @flow strict-local
9
+ * @format
10
+ */
11
+
12
+ // flowlint ambiguous-object-type:error
13
+
14
+ 'use strict';
15
+
16
+ const {
17
+ getModuleComponentKey,
18
+ getModuleOperationKey,
19
+ } = require('../store/RelayStoreUtils');
20
+
21
+ import type {NormalizationSplitOperation} from './NormalizationNode';
22
+ import type {JSResourceReference} from 'JSResourceReference';
23
+
24
+ export opaque type Local3DPayload<
25
+ +DocumentName: string,
26
+ +Response: {...},
27
+ > = Response;
28
+
29
+ function createPayloadFor3DField<+DocumentName: string, +Response: {...}>(
30
+ name: DocumentName,
31
+ operation: JSResourceReference<NormalizationSplitOperation>,
32
+ component: JSResourceReference<mixed>,
33
+ response: Response,
34
+ ): Local3DPayload<DocumentName, Response> {
35
+ const data = {
36
+ ...response,
37
+ };
38
+ data[getModuleComponentKey(name)] = component;
39
+ data[getModuleOperationKey(name)] = operation;
40
+ return data;
41
+ }
42
+
43
+ module.exports = createPayloadFor3DField;
@@ -0,0 +1,36 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ /**
16
+ * Recursively "deep" freezes the supplied object.
17
+ *
18
+ * For convenience, and for consistency with the behavior of `Object.freeze`,
19
+ * returns the now-frozen original object.
20
+ */
21
+ function deepFreeze<T: {...}>(object: T): T {
22
+ Object.freeze(object);
23
+ Object.getOwnPropertyNames(object).forEach(name => {
24
+ const property = object[name];
25
+ if (
26
+ property &&
27
+ typeof property === 'object' &&
28
+ !Object.isFrozen(property)
29
+ ) {
30
+ deepFreeze(property);
31
+ }
32
+ });
33
+ return object;
34
+ }
35
+
36
+ module.exports = deepFreeze;
@@ -0,0 +1,21 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ let id = 100000;
16
+
17
+ function generateID(): number {
18
+ return id++;
19
+ }
20
+
21
+ module.exports = generateID;
@@ -0,0 +1,52 @@
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
+ * @flow strict-local
8
+ * @format
9
+ * @emails oncall+relay
10
+ */
11
+
12
+ // flowlint ambiguous-object-type:error
13
+
14
+ 'use strict';
15
+
16
+ const stableCopy = require('./stableCopy');
17
+
18
+ const {
19
+ getDataIDsFromFragment,
20
+ getVariablesFromFragment,
21
+ getSelector,
22
+ } = require('../store/RelayModernSelector');
23
+
24
+ import type {ReaderFragment} from './ReaderNode';
25
+
26
+ function getFragmentIdentifier(
27
+ fragmentNode: ReaderFragment,
28
+ fragmentRef: mixed,
29
+ ): string {
30
+ const selector = getSelector(fragmentNode, fragmentRef);
31
+ const fragmentOwnerIdentifier =
32
+ selector == null
33
+ ? 'null'
34
+ : selector.kind === 'SingularReaderSelector'
35
+ ? selector.owner.identifier
36
+ : '[' +
37
+ selector.selectors.map(sel => sel.owner.identifier).join(',') +
38
+ ']';
39
+ const fragmentVariables = getVariablesFromFragment(fragmentNode, fragmentRef);
40
+ const dataIDs = getDataIDsFromFragment(fragmentNode, fragmentRef);
41
+ return (
42
+ fragmentOwnerIdentifier +
43
+ '/' +
44
+ fragmentNode.name +
45
+ '/' +
46
+ JSON.stringify(stableCopy(fragmentVariables)) +
47
+ '/' +
48
+ (JSON.stringify(dataIDs) ?? 'missing')
49
+ );
50
+ }
51
+
52
+ module.exports = getFragmentIdentifier;
@@ -0,0 +1,41 @@
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
+ * @flow
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ const invariant = require('invariant');
16
+
17
+ const {DEFAULT_HANDLE_KEY} = require('./RelayDefaultHandleKey');
18
+
19
+ /**
20
+ * @internal
21
+ *
22
+ * Helper to create a unique name for a handle field based on the handle name, handle key and
23
+ * source field.
24
+ */
25
+ function getRelayHandleKey(
26
+ handleName: string,
27
+ key: ?string,
28
+ fieldName: ?string,
29
+ ): string {
30
+ if (key && key !== DEFAULT_HANDLE_KEY) {
31
+ return `__${key}_${handleName}`;
32
+ }
33
+
34
+ invariant(
35
+ fieldName != null,
36
+ 'getRelayHandleKey: Expected either `fieldName` or `key` in `handle` to be provided',
37
+ );
38
+ return `__${fieldName}_${handleName}`;
39
+ }
40
+
41
+ module.exports = getRelayHandleKey;
@@ -0,0 +1,42 @@
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
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ const invariant = require('invariant');
16
+ const stableCopy = require('./stableCopy');
17
+
18
+ import type {RequestParameters} from './RelayConcreteNode';
19
+ import type {Variables} from './RelayRuntimeTypes';
20
+
21
+ export opaque type RequestIdentifier: string = string;
22
+
23
+ /**
24
+ * Returns a stable identifier for the given pair of `RequestParameters` +
25
+ * variables.
26
+ */
27
+ function getRequestIdentifier(
28
+ parameters: RequestParameters,
29
+ variables: Variables,
30
+ ): RequestIdentifier {
31
+ const requestID =
32
+ parameters.cacheID != null ? parameters.cacheID : parameters.id;
33
+ invariant(
34
+ requestID != null,
35
+ 'getRequestIdentifier: Expected request `%s` to have either a ' +
36
+ 'valid `id` or `cacheID` property',
37
+ parameters.name,
38
+ );
39
+ return requestID + JSON.stringify(stableCopy(variables));
40
+ }
41
+
42
+ module.exports = getRequestIdentifier;
@@ -0,0 +1,21 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ declare function isPromise(p: mixed): boolean %checks(p instanceof Promise);
16
+
17
+ function isPromise(p: $FlowFixMe): boolean {
18
+ return !!p && typeof p.then === 'function';
19
+ }
20
+
21
+ module.exports = isPromise;
@@ -0,0 +1,26 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ /**
16
+ * A fast test to determine if two values are equal scalars:
17
+ * - compares scalars such as booleans, strings, numbers by value
18
+ * - compares functions by identity
19
+ * - returns false for complex values, since these cannot be cheaply tested for
20
+ * equality (use `areEquals` instead)
21
+ */
22
+ function isScalarAndEqual(valueA: mixed, valueB: mixed): boolean {
23
+ return valueA === valueB && (valueA === null || typeof valueA !== 'object');
24
+ }
25
+
26
+ module.exports = isScalarAndEqual;
@@ -0,0 +1,76 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ /**
16
+ * Recycles subtrees from `prevData` by replacing equal subtrees in `nextData`.
17
+ */
18
+ function recycleNodesInto<T>(prevData: T, nextData: T): T {
19
+ if (
20
+ prevData === nextData ||
21
+ typeof prevData !== 'object' ||
22
+ !prevData ||
23
+ typeof nextData !== 'object' ||
24
+ !nextData
25
+ ) {
26
+ return nextData;
27
+ }
28
+ let canRecycle = false;
29
+
30
+ // Assign local variables to preserve Flow type refinement.
31
+ const prevArray = Array.isArray(prevData) ? prevData : null;
32
+ const nextArray = Array.isArray(nextData) ? nextData : null;
33
+ if (prevArray && nextArray) {
34
+ canRecycle =
35
+ nextArray.reduce((wasEqual, nextItem, ii) => {
36
+ const prevValue = prevArray[ii];
37
+ const nextValue = recycleNodesInto(prevValue, nextItem);
38
+ if (nextValue !== nextArray[ii]) {
39
+ if (__DEV__) {
40
+ if (!Object.isFrozen(nextArray)) {
41
+ nextArray[ii] = nextValue;
42
+ }
43
+ } else {
44
+ nextArray[ii] = nextValue;
45
+ }
46
+ }
47
+ return wasEqual && nextValue === prevArray[ii];
48
+ }, true) && prevArray.length === nextArray.length;
49
+ } else if (!prevArray && !nextArray) {
50
+ // Assign local variables to preserve Flow type refinement.
51
+ const prevObject = prevData;
52
+ const nextObject = nextData;
53
+ const prevKeys = Object.keys(prevObject);
54
+ const nextKeys = Object.keys(nextObject);
55
+ canRecycle =
56
+ nextKeys.reduce((wasEqual, key) => {
57
+ const prevValue = prevObject[key];
58
+ const nextValue = recycleNodesInto(prevValue, nextObject[key]);
59
+ if (nextValue !== nextObject[key]) {
60
+ if (__DEV__) {
61
+ if (!Object.isFrozen(nextObject)) {
62
+ // $FlowFixMe[cannot-write]
63
+ nextObject[key] = nextValue;
64
+ }
65
+ } else {
66
+ // $FlowFixMe[cannot-write]
67
+ nextObject[key] = nextValue;
68
+ }
69
+ }
70
+ return wasEqual && nextValue === prevObject[key];
71
+ }, true) && prevKeys.length === nextKeys.length;
72
+ }
73
+ return canRecycle ? prevData : nextData;
74
+ }
75
+
76
+ module.exports = recycleNodesInto;
@@ -0,0 +1,30 @@
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
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ var resolvedPromise = Promise.resolve();
16
+
17
+ /**
18
+ * An alternative to setImmediate based on Promise.
19
+ */
20
+ function resolveImmediate(callback: () => void) {
21
+ resolvedPromise.then(callback).catch(throwNext);
22
+ }
23
+
24
+ function throwNext(error) {
25
+ setTimeout(() => {
26
+ throw error;
27
+ }, 0);
28
+ }
29
+
30
+ module.exports = resolveImmediate;
@@ -0,0 +1,35 @@
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
+ * @flow
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ /**
16
+ * Creates a copy of the provided value, ensuring any nested objects have their
17
+ * keys sorted such that equivalent values would have identical JSON.stringify
18
+ * results.
19
+ */
20
+ function stableCopy<T: mixed>(value: T): T {
21
+ if (!value || typeof value !== 'object') {
22
+ return value;
23
+ }
24
+ if (Array.isArray(value)) {
25
+ return value.map(stableCopy);
26
+ }
27
+ const keys = Object.keys(value).sort();
28
+ const stable = {};
29
+ for (let i = 0; i < keys.length; i++) {
30
+ stable[keys[i]] = stableCopy(value[keys[i]]);
31
+ }
32
+ return (stable: any);
33
+ }
34
+
35
+ module.exports = stableCopy;
@@ -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
- *
8
- * @format
9
- */
10
- 'use strict';
11
-
12
- var _require = require('../store/RelayStoreUtils'),
13
- ROOT_TYPE = _require.ROOT_TYPE;
14
-
15
- var _require2 = require('../store/ViewerPattern'),
16
- VIEWER_ID = _require2.VIEWER_ID;
17
-
18
- var missingViewerFieldHandler = {
19
- kind: 'linked',
20
- handle: function handle(field, record, argValues) {
21
- if (record != null && record.__typename === ROOT_TYPE && field.name === 'viewer') {
22
- return VIEWER_ID;
23
- }
24
- }
25
- };
26
- module.exports = [missingViewerFieldHandler];
@@ -1,36 +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
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
-
13
- var RelayFeatureFlags = require('../util/RelayFeatureFlags');
14
-
15
- var _require = require('../store/RelayStoreUtils'),
16
- ROOT_TYPE = _require.ROOT_TYPE;
17
-
18
- var _require2 = require('../store/ViewerPattern'),
19
- VIEWER_ID = _require2.VIEWER_ID;
20
-
21
- function getHandler() {
22
- if (RelayFeatureFlags.ENABLE_MISSING_VIEWER_FIELD_HANDLER) {
23
- return [{
24
- kind: 'linked',
25
- handle: function handle(field, record, argValues) {
26
- if (record != null && record.__typename === ROOT_TYPE && field.name === 'viewer') {
27
- return VIEWER_ID;
28
- }
29
- }
30
- }];
31
- }
32
-
33
- return [];
34
- }
35
-
36
- module.exports = getHandler;
@@ -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 RelayConcreteNode = require('../util/RelayConcreteNode');
13
-
14
- var invariant = require("fbjs/lib/invariant");
15
-
16
- /**
17
- * Runtime function to correspond to the `graphql` tagged template function.
18
- * All calls to this function should be transformed by the plugin.
19
- */
20
- function graphql(strings) {
21
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'graphql: Unexpected invocation at runtime. Either the Babel transform ' + 'was not set up, or it failed to identify this call site. Make sure it ' + 'is being used verbatim as `graphql`.') : invariant(false) : void 0;
22
- }
23
-
24
- function getNode(taggedNode) {
25
- if (typeof taggedNode !== 'function') {
26
- return taggedNode;
27
- }
28
-
29
- var data = taggedNode(); // Support for languages that work (best) with ES6 modules, such as TypeScript.
30
-
31
- return data["default"] ? data["default"] : data;
32
- }
33
-
34
- function isFragment(node) {
35
- var fragment = getNode(node);
36
- return typeof fragment === 'object' && fragment !== null && fragment.kind === RelayConcreteNode.FRAGMENT;
37
- }
38
-
39
- function isRequest(node) {
40
- var request = getNode(node);
41
- return typeof request === 'object' && request !== null && request.kind === RelayConcreteNode.REQUEST;
42
- }
43
-
44
- function isInlineDataFragment(node) {
45
- var fragment = getNode(node);
46
- return typeof fragment === 'object' && fragment !== null && fragment.kind === RelayConcreteNode.INLINE_DATA_FRAGMENT;
47
- }
48
-
49
- function getFragment(taggedNode) {
50
- var fragment = getNode(taggedNode);
51
- !isFragment(fragment) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernGraphQLTag: Expected a fragment, got `%s`.', JSON.stringify(fragment)) : invariant(false) : void 0;
52
- return fragment;
53
- }
54
-
55
- function getPaginationFragment(taggedNode) {
56
- var _fragment$metadata;
57
-
58
- var fragment = getFragment(taggedNode);
59
- var refetch = (_fragment$metadata = fragment.metadata) === null || _fragment$metadata === void 0 ? void 0 : _fragment$metadata.refetch;
60
- var connection = refetch === null || refetch === void 0 ? void 0 : refetch.connection;
61
-
62
- if (refetch === null || typeof refetch !== 'object' || connection === null || typeof connection !== 'object') {
63
- return null;
64
- }
65
-
66
- return fragment;
67
- }
68
-
69
- function getRefetchableFragment(taggedNode) {
70
- var _fragment$metadata2;
71
-
72
- var fragment = getFragment(taggedNode);
73
- var refetch = (_fragment$metadata2 = fragment.metadata) === null || _fragment$metadata2 === void 0 ? void 0 : _fragment$metadata2.refetch;
74
-
75
- if (refetch === null || typeof refetch !== 'object') {
76
- return null;
77
- }
78
-
79
- return fragment;
80
- }
81
-
82
- function getRequest(taggedNode) {
83
- var request = getNode(taggedNode);
84
- !isRequest(request) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernGraphQLTag: Expected a request, got `%s`.', JSON.stringify(request)) : invariant(false) : void 0;
85
- return request;
86
- }
87
-
88
- function getInlineDataFragment(taggedNode) {
89
- var fragment = getNode(taggedNode);
90
- !isInlineDataFragment(fragment) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernGraphQLTag: Expected an inline data fragment, got `%s`.', JSON.stringify(fragment)) : invariant(false) : void 0;
91
- return fragment;
92
- }
93
-
94
- module.exports = {
95
- getFragment: getFragment,
96
- getPaginationFragment: getPaginationFragment,
97
- getRefetchableFragment: getRefetchableFragment,
98
- getRequest: getRequest,
99
- getInlineDataFragment: getInlineDataFragment,
100
- graphql: graphql,
101
- isFragment: isFragment,
102
- isRequest: isRequest,
103
- isInlineDataFragment: isInlineDataFragment
104
- };
@@ -1,37 +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
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
-
13
- // Intentionally inexact
14
- // Note: The phantom TEdge type allows propagation of the `edges` field
15
- // selections.
16
- // eslint-disable-next-line no-unused-vars
17
- var CONNECTION_KEY = '__connection';
18
- var CONNECTION_TYPENAME = '__ConnectionRecord';
19
-
20
- function createConnectionID(parentID, label) {
21
- return "connection:".concat(parentID, ":").concat(label);
22
- }
23
-
24
- function createConnectionRecord(connectionID) {
25
- return {
26
- __id: connectionID,
27
- __typename: '__ConnectionRecord',
28
- events: []
29
- };
30
- }
31
-
32
- module.exports = {
33
- createConnectionID: createConnectionID,
34
- createConnectionRecord: createConnectionRecord,
35
- CONNECTION_KEY: CONNECTION_KEY,
36
- CONNECTION_TYPENAME: CONNECTION_TYPENAME
37
- };