relay-runtime 11.0.2 → 13.0.0-rc.2
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.
- package/README.md +67 -0
- package/handlers/RelayDefaultHandlerProvider.js.flow +3 -3
- package/handlers/connection/ConnectionHandler.js.flow +9 -18
- package/handlers/connection/ConnectionInterface.js.flow +1 -1
- package/handlers/connection/MutationHandlers.js.flow +8 -12
- package/index.js +1 -1
- package/index.js.flow +57 -35
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +13 -19
- package/lib/handlers/connection/ConnectionInterface.js +1 -1
- package/lib/handlers/connection/MutationHandlers.js +4 -7
- package/lib/index.js +59 -44
- package/lib/multi-actor-environment/ActorIdentifier.js +12 -2
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +64 -20
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +324 -61
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +1 -1
- package/lib/multi-actor-environment/index.js +6 -2
- package/lib/mutations/RelayDeclarativeMutationConfig.js +5 -2
- package/lib/mutations/RelayRecordProxy.js +4 -3
- package/lib/mutations/RelayRecordSourceMutator.js +4 -3
- package/lib/mutations/RelayRecordSourceProxy.js +13 -5
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +19 -6
- package/lib/mutations/applyOptimisticMutation.js +7 -7
- package/lib/mutations/commitLocalUpdate.js +1 -1
- package/lib/mutations/commitMutation.js +15 -11
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +242 -0
- package/lib/mutations/validateMutation.js +11 -6
- package/lib/network/ConvertToExecuteFunction.js +3 -2
- package/lib/network/RelayNetwork.js +4 -3
- package/lib/network/RelayNetworkTypes.js +1 -1
- package/lib/network/RelayObservable.js +1 -1
- package/lib/network/RelayQueryResponseCache.js +22 -6
- package/lib/network/wrapNetworkWithLogObserver.js +79 -0
- package/lib/query/GraphQLTag.js +3 -2
- package/lib/query/PreloadableQueryRegistry.js +1 -1
- package/lib/query/fetchQuery.js +7 -6
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/query/fetchQuery_DEPRECATED.js +3 -2
- package/lib/store/ClientID.js +8 -2
- package/lib/store/DataChecker.js +124 -55
- package/lib/store/OperationExecutor.js +489 -215
- package/lib/store/RelayConcreteVariables.js +27 -9
- package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
- package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
- package/lib/store/RelayModernEnvironment.js +100 -120
- package/lib/store/RelayModernFragmentSpecResolver.js +53 -27
- package/lib/store/RelayModernOperationDescriptor.js +3 -2
- package/lib/store/RelayModernRecord.js +48 -13
- package/lib/store/RelayModernSelector.js +15 -9
- package/lib/store/RelayModernStore.js +56 -23
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayOptimisticRecordSource.js +1 -1
- package/lib/store/RelayPublishQueue.js +35 -11
- package/lib/store/RelayReader.js +257 -72
- package/lib/store/RelayRecordSource.js +88 -4
- package/lib/store/RelayRecordState.js +1 -1
- package/lib/store/RelayReferenceMarker.js +34 -22
- package/lib/store/RelayResponseNormalizer.js +172 -96
- package/lib/store/RelayStoreReactFlightUtils.js +5 -11
- package/lib/store/RelayStoreSubscriptions.js +15 -10
- package/lib/store/RelayStoreTypes.js +1 -1
- package/lib/store/RelayStoreUtils.js +13 -8
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +10 -6
- package/lib/store/StoreInspector.js +1 -1
- package/lib/store/TypeID.js +1 -1
- package/lib/store/ViewerPattern.js +1 -1
- package/lib/store/cloneRelayHandleSourceField.js +6 -5
- package/lib/store/cloneRelayScalarHandleSourceField.js +6 -5
- package/lib/store/createFragmentSpecResolver.js +1 -1
- package/lib/store/createRelayContext.js +5 -3
- package/lib/store/defaultGetDataID.js +1 -1
- package/lib/store/defaultRequiredFieldLogger.js +1 -1
- package/lib/store/hasOverlappingIDs.js +1 -1
- package/lib/store/isRelayModernEnvironment.js +1 -1
- package/lib/store/normalizeRelayPayload.js +1 -1
- package/lib/store/readInlineData.js +7 -3
- package/lib/subscription/requestSubscription.js +32 -34
- package/lib/util/JSResourceTypes.flow.js +1 -1
- package/lib/util/NormalizationNode.js +1 -1
- package/lib/util/ReaderNode.js +1 -1
- package/lib/util/RelayConcreteNode.js +3 -1
- package/lib/util/RelayDefaultHandleKey.js +1 -1
- package/lib/util/RelayError.js +1 -1
- package/lib/util/RelayFeatureFlags.js +10 -7
- package/lib/util/RelayProfiler.js +1 -1
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/RelayRuntimeTypes.js +1 -7
- package/lib/util/StringInterner.js +71 -0
- package/lib/util/createPayloadFor3DField.js +1 -1
- package/lib/util/deepFreeze.js +1 -1
- package/lib/util/generateID.js +1 -1
- package/lib/util/getAllRootVariables.js +29 -0
- package/lib/util/getFragmentIdentifier.js +16 -8
- package/lib/util/getOperation.js +3 -2
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +66 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +3 -3
- package/lib/util/getRequestIdentifier.js +3 -3
- package/lib/util/getValueAtPath.js +51 -0
- package/lib/util/isEmptyObject.js +2 -2
- package/lib/util/isPromise.js +1 -1
- package/lib/util/isScalarAndEqual.js +1 -1
- package/lib/util/recycleNodesInto.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +26 -0
- package/lib/util/reportMissingRequiredFields.js +1 -1
- package/lib/util/resolveImmediate.js +1 -1
- package/lib/util/stableCopy.js +1 -1
- package/lib/util/withDuration.js +31 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +18 -2
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +94 -58
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +366 -93
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +88 -23
- package/multi-actor-environment/index.js.flow +3 -1
- package/mutations/RelayDeclarativeMutationConfig.js.flow +33 -27
- package/mutations/RelayRecordProxy.js.flow +5 -6
- package/mutations/RelayRecordSourceMutator.js.flow +5 -7
- package/mutations/RelayRecordSourceProxy.js.flow +20 -11
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +23 -8
- package/mutations/applyOptimisticMutation.js.flow +14 -15
- package/mutations/commitLocalUpdate.js.flow +2 -2
- package/mutations/commitMutation.js.flow +36 -47
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +318 -0
- package/mutations/validateMutation.js.flow +27 -17
- package/network/ConvertToExecuteFunction.js.flow +3 -3
- package/network/RelayNetwork.js.flow +5 -6
- package/network/RelayNetworkTypes.js.flow +1 -1
- package/network/RelayObservable.js.flow +2 -2
- package/network/RelayQueryResponseCache.js.flow +35 -22
- package/network/wrapNetworkWithLogObserver.js.flow +99 -0
- package/package.json +2 -2
- package/query/GraphQLTag.js.flow +11 -11
- package/query/PreloadableQueryRegistry.js.flow +5 -3
- package/query/fetchQuery.js.flow +19 -19
- package/query/fetchQueryInternal.js.flow +7 -10
- package/query/fetchQuery_DEPRECATED.js.flow +7 -7
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +15 -4
- package/store/DataChecker.js.flow +142 -60
- package/store/OperationExecutor.js.flow +575 -320
- package/store/RelayConcreteVariables.js.flow +28 -9
- package/store/RelayExperimentalGraphResponseHandler.js.flow +121 -0
- package/store/RelayExperimentalGraphResponseTransform.js.flow +470 -0
- package/store/RelayModernEnvironment.js.flow +91 -115
- package/store/RelayModernFragmentSpecResolver.js.flow +56 -32
- package/store/RelayModernOperationDescriptor.js.flow +13 -8
- package/store/RelayModernRecord.js.flow +68 -12
- package/store/RelayModernSelector.js.flow +25 -15
- package/store/RelayModernStore.js.flow +67 -32
- package/store/RelayOperationTracker.js.flow +60 -44
- package/store/RelayOptimisticRecordSource.js.flow +3 -3
- package/store/RelayPublishQueue.js.flow +74 -32
- package/store/RelayReader.js.flow +319 -100
- package/store/RelayRecordSource.js.flow +73 -7
- package/store/RelayRecordState.js.flow +1 -1
- package/store/RelayReferenceMarker.js.flow +41 -27
- package/store/RelayResponseNormalizer.js.flow +204 -86
- package/store/RelayStoreReactFlightUtils.js.flow +5 -12
- package/store/RelayStoreSubscriptions.js.flow +20 -12
- package/store/RelayStoreTypes.js.flow +200 -41
- package/store/RelayStoreUtils.js.flow +25 -12
- package/store/ResolverCache.js.flow +249 -0
- package/store/ResolverFragments.js.flow +16 -20
- package/store/StoreInspector.js.flow +3 -3
- package/store/TypeID.js.flow +2 -2
- package/store/ViewerPattern.js.flow +3 -3
- package/store/cloneRelayHandleSourceField.js.flow +6 -7
- package/store/cloneRelayScalarHandleSourceField.js.flow +6 -7
- package/store/createFragmentSpecResolver.js.flow +4 -5
- package/store/createRelayContext.js.flow +4 -4
- package/store/defaultGetDataID.js.flow +1 -1
- package/store/defaultRequiredFieldLogger.js.flow +1 -1
- package/store/hasOverlappingIDs.js.flow +1 -1
- package/store/isRelayModernEnvironment.js.flow +1 -1
- package/store/normalizeRelayPayload.js.flow +7 -8
- package/store/readInlineData.js.flow +8 -9
- package/subscription/requestSubscription.js.flow +55 -51
- package/util/JSResourceTypes.flow.js.flow +1 -1
- package/util/NormalizationNode.js.flow +11 -4
- package/util/ReaderNode.js.flow +25 -2
- package/util/RelayConcreteNode.js.flow +5 -1
- package/util/RelayDefaultHandleKey.js.flow +1 -1
- package/util/RelayError.js.flow +1 -1
- package/util/RelayFeatureFlags.js.flow +23 -15
- package/util/RelayProfiler.js.flow +1 -1
- package/util/RelayReplaySubject.js.flow +10 -10
- package/util/RelayRuntimeTypes.js.flow +70 -3
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +4 -4
- package/util/deepFreeze.js.flow +1 -1
- package/util/generateID.js.flow +1 -1
- package/util/getAllRootVariables.js.flow +36 -0
- package/util/getFragmentIdentifier.js.flow +28 -16
- package/util/getOperation.js.flow +3 -3
- package/util/getPaginationMetadata.js.flow +69 -0
- package/util/getPaginationVariables.js.flow +108 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +76 -0
- package/util/getRelayHandleKey.js.flow +2 -3
- package/util/getRequestIdentifier.js.flow +4 -4
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +2 -1
- package/util/isPromise.js.flow +1 -1
- package/util/isScalarAndEqual.js.flow +1 -1
- package/util/recycleNodesInto.js.flow +1 -1
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/reportMissingRequiredFields.js.flow +1 -1
- package/util/resolveImmediate.js.flow +2 -2
- package/util/stableCopy.js.flow +1 -1
- package/util/withDuration.js.flow +32 -0
- package/lib/store/RelayRecordSourceMapImpl.js +0 -107
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
- package/store/RelayRecordSourceMapImpl.js.flow +0 -91
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -12,18 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayDeclarativeMutationConfig = require('../mutations/RelayDeclarativeMutationConfig');
|
|
16
|
-
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
17
|
-
|
|
18
|
-
const warning = require('warning');
|
|
19
|
-
|
|
20
|
-
const {getRequest} = require('../query/GraphQLTag');
|
|
21
|
-
const {generateUniqueClientID} = require('../store/ClientID');
|
|
22
|
-
const {
|
|
23
|
-
createOperationDescriptor,
|
|
24
|
-
} = require('../store/RelayModernOperationDescriptor');
|
|
25
|
-
const {createReaderSelector} = require('../store/RelayModernSelector');
|
|
26
|
-
|
|
27
15
|
import type {DeclarativeMutationConfig} from '../mutations/RelayDeclarativeMutationConfig';
|
|
28
16
|
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
29
17
|
import type {
|
|
@@ -36,7 +24,33 @@ import type {
|
|
|
36
24
|
Variables,
|
|
37
25
|
} from '../util/RelayRuntimeTypes';
|
|
38
26
|
|
|
39
|
-
|
|
27
|
+
const RelayDeclarativeMutationConfig = require('../mutations/RelayDeclarativeMutationConfig');
|
|
28
|
+
const {getRequest} = require('../query/GraphQLTag');
|
|
29
|
+
const {
|
|
30
|
+
createOperationDescriptor,
|
|
31
|
+
} = require('../store/RelayModernOperationDescriptor');
|
|
32
|
+
const {createReaderSelector} = require('../store/RelayModernSelector');
|
|
33
|
+
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
34
|
+
const warning = require('warning');
|
|
35
|
+
|
|
36
|
+
export type SubscriptionParameters = {|
|
|
37
|
+
+response: {...},
|
|
38
|
+
+variables: interface {},
|
|
39
|
+
+rawResponse?: {...},
|
|
40
|
+
|};
|
|
41
|
+
|
|
42
|
+
export type GraphQLSubscriptionConfig<T: SubscriptionParameters> = {|
|
|
43
|
+
configs?: Array<DeclarativeMutationConfig>,
|
|
44
|
+
cacheConfig?: CacheConfig,
|
|
45
|
+
subscription: GraphQLTaggedNode,
|
|
46
|
+
variables: T['variables'],
|
|
47
|
+
onCompleted?: ?() => void,
|
|
48
|
+
onError?: ?(error: Error) => void,
|
|
49
|
+
onNext?: ?(response: ?T['response']) => void,
|
|
50
|
+
updater?: ?SelectorStoreUpdater<T['response']>,
|
|
51
|
+
|};
|
|
52
|
+
|
|
53
|
+
export type DEPRECATED_GraphQLSubscriptionConfig<TSubscriptionPayload> = {|
|
|
40
54
|
configs?: Array<DeclarativeMutationConfig>,
|
|
41
55
|
cacheConfig?: CacheConfig,
|
|
42
56
|
subscription: GraphQLTaggedNode,
|
|
@@ -44,32 +58,23 @@ export type GraphQLSubscriptionConfig<TSubscriptionPayload> = {|
|
|
|
44
58
|
onCompleted?: ?() => void,
|
|
45
59
|
onError?: ?(error: Error) => void,
|
|
46
60
|
onNext?: ?(response: ?TSubscriptionPayload) => void,
|
|
47
|
-
updater?: ?SelectorStoreUpdater
|
|
61
|
+
updater?: ?SelectorStoreUpdater<TSubscriptionPayload>,
|
|
48
62
|
|};
|
|
49
63
|
|
|
50
64
|
function requestSubscription<TSubscriptionPayload>(
|
|
51
65
|
environment: IEnvironment,
|
|
52
|
-
config:
|
|
66
|
+
config: DEPRECATED_GraphQLSubscriptionConfig<TSubscriptionPayload>,
|
|
53
67
|
): Disposable {
|
|
54
68
|
const subscription = getRequest(config.subscription);
|
|
55
69
|
if (subscription.params.operationKind !== 'subscription') {
|
|
56
70
|
throw new Error('requestSubscription: Must use Subscription operation');
|
|
57
71
|
}
|
|
58
|
-
const {
|
|
59
|
-
|
|
60
|
-
onCompleted,
|
|
61
|
-
onError,
|
|
62
|
-
onNext,
|
|
63
|
-
variables,
|
|
64
|
-
cacheConfig,
|
|
65
|
-
} = config;
|
|
72
|
+
const {configs, onCompleted, onError, onNext, variables, cacheConfig} =
|
|
73
|
+
config;
|
|
66
74
|
const operation = createOperationDescriptor(
|
|
67
75
|
subscription,
|
|
68
76
|
variables,
|
|
69
77
|
cacheConfig,
|
|
70
|
-
RelayFeatureFlags.ENABLE_UNIQUE_SUBSCRIPTION_ROOT
|
|
71
|
-
? generateUniqueClientID()
|
|
72
|
-
: undefined,
|
|
73
78
|
);
|
|
74
79
|
|
|
75
80
|
warning(
|
|
@@ -87,34 +92,33 @@ function requestSubscription<TSubscriptionPayload>(
|
|
|
87
92
|
: config;
|
|
88
93
|
|
|
89
94
|
const sub = environment
|
|
90
|
-
.
|
|
95
|
+
.executeSubscription({
|
|
91
96
|
operation,
|
|
92
97
|
updater,
|
|
93
98
|
})
|
|
94
|
-
.map(responses => {
|
|
95
|
-
let selector = operation.fragment;
|
|
96
|
-
if (RelayFeatureFlags.ENABLE_UNIQUE_SUBSCRIPTION_ROOT) {
|
|
97
|
-
let nextID;
|
|
98
|
-
if (Array.isArray(responses)) {
|
|
99
|
-
nextID = responses[0]?.extensions?.__relay_subscription_root_id;
|
|
100
|
-
} else {
|
|
101
|
-
nextID = responses.extensions?.__relay_subscription_root_id;
|
|
102
|
-
}
|
|
103
|
-
if (typeof nextID === 'string') {
|
|
104
|
-
selector = createReaderSelector(
|
|
105
|
-
selector.node,
|
|
106
|
-
nextID,
|
|
107
|
-
selector.variables,
|
|
108
|
-
selector.owner,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const data = environment.lookup(selector).data;
|
|
113
|
-
// $FlowFixMe[incompatible-cast]
|
|
114
|
-
return (data: TSubscriptionPayload);
|
|
115
|
-
})
|
|
116
99
|
.subscribe({
|
|
117
|
-
next:
|
|
100
|
+
next: responses => {
|
|
101
|
+
if (onNext != null) {
|
|
102
|
+
let selector = operation.fragment;
|
|
103
|
+
let nextID;
|
|
104
|
+
if (Array.isArray(responses)) {
|
|
105
|
+
nextID = responses[0]?.extensions?.__relay_subscription_root_id;
|
|
106
|
+
} else {
|
|
107
|
+
nextID = responses.extensions?.__relay_subscription_root_id;
|
|
108
|
+
}
|
|
109
|
+
if (typeof nextID === 'string') {
|
|
110
|
+
selector = createReaderSelector(
|
|
111
|
+
selector.node,
|
|
112
|
+
nextID,
|
|
113
|
+
selector.variables,
|
|
114
|
+
selector.owner,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
const data = environment.lookup(selector).data;
|
|
118
|
+
// $FlowFixMe[incompatible-cast]
|
|
119
|
+
onNext((data: TSubscriptionPayload));
|
|
120
|
+
}
|
|
121
|
+
},
|
|
118
122
|
error: onError,
|
|
119
123
|
complete: onCompleted,
|
|
120
124
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -87,7 +87,7 @@ export type NormalizationInlineFragment = {|
|
|
|
87
87
|
|
|
88
88
|
export type NormalizationFragmentSpread = {|
|
|
89
89
|
+kind: 'FragmentSpread',
|
|
90
|
-
+fragment:
|
|
90
|
+
+fragment: NormalizationSplitOperation,
|
|
91
91
|
+args: ?$ReadOnlyArray<NormalizationArgument>,
|
|
92
92
|
|};
|
|
93
93
|
|
|
@@ -102,7 +102,13 @@ export type NormalizationLinkedField = {|
|
|
|
102
102
|
+selections: $ReadOnlyArray<NormalizationSelection>,
|
|
103
103
|
|};
|
|
104
104
|
|
|
105
|
+
export type NormalizationActorChange = {|
|
|
106
|
+
+kind: 'ActorChange',
|
|
107
|
+
+linkedField: NormalizationLinkedField,
|
|
108
|
+
|};
|
|
109
|
+
|
|
105
110
|
export type NormalizationModuleImport = {|
|
|
111
|
+
+args: ?$ReadOnlyArray<NormalizationArgument>,
|
|
106
112
|
+kind: 'ModuleImport',
|
|
107
113
|
+documentName: string,
|
|
108
114
|
+fragmentPropName: string,
|
|
@@ -155,6 +161,7 @@ export type NormalizationFlightField = {|
|
|
|
155
161
|
|};
|
|
156
162
|
|
|
157
163
|
export type NormalizationClientComponent = {|
|
|
164
|
+
+args?: ?$ReadOnlyArray<NormalizationArgument>,
|
|
158
165
|
+kind: 'ClientComponent',
|
|
159
166
|
+fragment: NormalizationNode,
|
|
160
167
|
|};
|
|
@@ -176,9 +183,11 @@ export type NormalizationSelection =
|
|
|
176
183
|
| NormalizationInlineFragment
|
|
177
184
|
| NormalizationModuleImport
|
|
178
185
|
| NormalizationStream
|
|
186
|
+
| NormalizationActorChange
|
|
179
187
|
| NormalizationTypeDiscriminator;
|
|
180
188
|
|
|
181
189
|
export type NormalizationSplitOperation = {|
|
|
190
|
+
+argumentDefinitions?: $ReadOnlyArray<NormalizationLocalArgumentDefinition>,
|
|
182
191
|
+kind: 'SplitOperation',
|
|
183
192
|
+name: string,
|
|
184
193
|
+metadata: ?{+[key: string]: mixed, ...},
|
|
@@ -189,8 +198,6 @@ export type NormalizationStream = {|
|
|
|
189
198
|
+if: string | null,
|
|
190
199
|
+kind: 'Stream',
|
|
191
200
|
+label: string,
|
|
192
|
-
+useCustomizedBatch: string | null,
|
|
193
|
-
+metadata: ?{+[key: string]: mixed, ...},
|
|
194
201
|
+selections: $ReadOnlyArray<NormalizationSelection>,
|
|
195
202
|
|};
|
|
196
203
|
|
package/util/ReaderNode.js.flow
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -108,7 +108,10 @@ export type ReaderClientExtension = {|
|
|
|
108
108
|
+selections: $ReadOnlyArray<ReaderSelection>,
|
|
109
109
|
|};
|
|
110
110
|
|
|
111
|
-
export type ReaderField =
|
|
111
|
+
export type ReaderField =
|
|
112
|
+
| ReaderScalarField
|
|
113
|
+
| ReaderLinkedField
|
|
114
|
+
| ReaderRelayResolver;
|
|
112
115
|
|
|
113
116
|
export type ReaderRootArgument = {|
|
|
114
117
|
+kind: 'RootArgument',
|
|
@@ -133,7 +136,17 @@ export type ReaderLinkedField = {|
|
|
|
133
136
|
+selections: $ReadOnlyArray<ReaderSelection>,
|
|
134
137
|
|};
|
|
135
138
|
|
|
139
|
+
export type ReaderActorChange = {|
|
|
140
|
+
+kind: 'ActorChange',
|
|
141
|
+
+alias: ?string,
|
|
142
|
+
+name: string,
|
|
143
|
+
+storageKey: ?string,
|
|
144
|
+
+args: ?$ReadOnlyArray<ReaderArgument>,
|
|
145
|
+
+fragmentSpread: ReaderFragmentSpread,
|
|
146
|
+
|};
|
|
147
|
+
|
|
136
148
|
export type ReaderModuleImport = {|
|
|
149
|
+
+args?: ?$ReadOnlyArray<ReaderArgument>,
|
|
137
150
|
+kind: 'ModuleImport',
|
|
138
151
|
+documentName: string,
|
|
139
152
|
+fragmentPropName: string,
|
|
@@ -213,16 +226,26 @@ export type ReaderRelayResolver = {|
|
|
|
213
226
|
+fragment: ReaderFragmentSpread,
|
|
214
227
|
+resolverModule: (rootKey: {
|
|
215
228
|
+$data?: any, // flowlint-line unclear-type:off
|
|
229
|
+
+$fragmentSpreads: any, // flowlint-line unclear-type:off
|
|
216
230
|
+$fragmentRefs: any, // flowlint-line unclear-type:off
|
|
217
231
|
...
|
|
218
232
|
}) => mixed,
|
|
219
233
|
|};
|
|
220
234
|
|
|
235
|
+
export type ReaderClientEdge = {|
|
|
236
|
+
+kind: 'ClientEdge',
|
|
237
|
+
+linkedField: ReaderLinkedField,
|
|
238
|
+
+operation: ConcreteRequest,
|
|
239
|
+
+backingField: ReaderRelayResolver | ReaderClientExtension,
|
|
240
|
+
|};
|
|
241
|
+
|
|
221
242
|
export type ReaderSelection =
|
|
222
243
|
| ReaderCondition
|
|
244
|
+
| ReaderClientEdge
|
|
223
245
|
| ReaderClientExtension
|
|
224
246
|
| ReaderDefer
|
|
225
247
|
| ReaderField
|
|
248
|
+
| ReaderActorChange
|
|
226
249
|
| ReaderFlightField
|
|
227
250
|
| ReaderFragmentSpread
|
|
228
251
|
| ReaderInlineDataFragmentSpread
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -48,6 +48,7 @@ export type RequestParameters =
|
|
|
48
48
|
// common fields
|
|
49
49
|
+name: string,
|
|
50
50
|
+operationKind: 'mutation' | 'query' | 'subscription',
|
|
51
|
+
+providedVariables?: {[key: string]: {|get(): mixed|}},
|
|
51
52
|
+metadata: {[key: string]: mixed, ...},
|
|
52
53
|
|}
|
|
53
54
|
| {|
|
|
@@ -57,6 +58,7 @@ export type RequestParameters =
|
|
|
57
58
|
// common fields
|
|
58
59
|
+name: string,
|
|
59
60
|
+operationKind: 'mutation' | 'query' | 'subscription',
|
|
61
|
+
+providedVariables?: {[key: string]: {|get(): mixed|}},
|
|
60
62
|
+metadata: {[key: string]: mixed, ...},
|
|
61
63
|
|};
|
|
62
64
|
|
|
@@ -67,8 +69,10 @@ export type GeneratedNode =
|
|
|
67
69
|
| NormalizationSplitOperation;
|
|
68
70
|
|
|
69
71
|
const RelayConcreteNode = {
|
|
72
|
+
ACTOR_CHANGE: 'ActorChange',
|
|
70
73
|
CONDITION: 'Condition',
|
|
71
74
|
CLIENT_COMPONENT: 'ClientComponent',
|
|
75
|
+
CLIENT_EDGE: 'ClientEdge',
|
|
72
76
|
CLIENT_EXTENSION: 'ClientExtension',
|
|
73
77
|
DEFER: 'Defer',
|
|
74
78
|
CONNECTION: 'Connection',
|
package/util/RelayError.js.flow
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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
|
-
* @flow strict
|
|
7
|
+
* @flow strict-local
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -12,40 +12,48 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
type
|
|
15
|
+
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
16
|
+
|
|
17
|
+
export type FeatureFlags = {|
|
|
18
|
+
DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES: boolean,
|
|
19
|
+
ENABLE_CLIENT_EDGES: boolean,
|
|
16
20
|
ENABLE_VARIABLE_CONNECTION_KEY: boolean,
|
|
17
21
|
ENABLE_PARTIAL_RENDERING_DEFAULT: boolean,
|
|
18
|
-
ENABLE_RELAY_CONTAINERS_SUSPENSE: boolean,
|
|
19
|
-
ENABLE_PRECISE_TYPE_REFINEMENT: boolean,
|
|
20
22
|
ENABLE_REACT_FLIGHT_COMPONENT_FIELD: boolean,
|
|
21
|
-
ENABLE_REQUIRED_DIRECTIVES: boolean | string,
|
|
22
23
|
ENABLE_RELAY_RESOLVERS: boolean,
|
|
23
24
|
ENABLE_GETFRAGMENTIDENTIFIER_OPTIMIZATION: boolean,
|
|
24
25
|
ENABLE_FRIENDLY_QUERY_NAME_GQL_URL: boolean,
|
|
25
|
-
ENABLE_STORE_SUBSCRIPTIONS_REFACTOR: boolean,
|
|
26
26
|
ENABLE_LOAD_QUERY_REQUEST_DEDUPING: boolean,
|
|
27
27
|
ENABLE_DO_NOT_WRAP_LIVE_QUERY: boolean,
|
|
28
28
|
ENABLE_NOTIFY_SUBSCRIPTION: boolean,
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
BATCH_ASYNC_MODULE_UPDATES_FN: ?(() => void) => Disposable,
|
|
30
|
+
ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT: boolean,
|
|
31
|
+
ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT: boolean,
|
|
32
|
+
MAX_DATA_ID_LENGTH: ?number,
|
|
33
|
+
REFACTOR_SUSPENSE_RESOURCE: boolean,
|
|
34
|
+
STRING_INTERN_LEVEL: number,
|
|
35
|
+
USE_REACT_CACHE: boolean,
|
|
31
36
|
|};
|
|
32
37
|
|
|
33
38
|
const RelayFeatureFlags: FeatureFlags = {
|
|
39
|
+
DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES: false,
|
|
40
|
+
ENABLE_CLIENT_EDGES: false,
|
|
34
41
|
ENABLE_VARIABLE_CONNECTION_KEY: false,
|
|
35
42
|
ENABLE_PARTIAL_RENDERING_DEFAULT: true,
|
|
36
|
-
ENABLE_RELAY_CONTAINERS_SUSPENSE: true,
|
|
37
|
-
ENABLE_PRECISE_TYPE_REFINEMENT: false,
|
|
38
43
|
ENABLE_REACT_FLIGHT_COMPONENT_FIELD: false,
|
|
39
|
-
ENABLE_REQUIRED_DIRECTIVES: false,
|
|
40
44
|
ENABLE_RELAY_RESOLVERS: false,
|
|
41
45
|
ENABLE_GETFRAGMENTIDENTIFIER_OPTIMIZATION: false,
|
|
42
46
|
ENABLE_FRIENDLY_QUERY_NAME_GQL_URL: false,
|
|
43
|
-
ENABLE_STORE_SUBSCRIPTIONS_REFACTOR: false,
|
|
44
47
|
ENABLE_LOAD_QUERY_REQUEST_DEDUPING: true,
|
|
45
48
|
ENABLE_DO_NOT_WRAP_LIVE_QUERY: false,
|
|
46
49
|
ENABLE_NOTIFY_SUBSCRIPTION: false,
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
BATCH_ASYNC_MODULE_UPDATES_FN: null,
|
|
51
|
+
ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT: false,
|
|
52
|
+
ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT: false,
|
|
53
|
+
MAX_DATA_ID_LENGTH: null,
|
|
54
|
+
REFACTOR_SUSPENSE_RESOURCE: true,
|
|
55
|
+
STRING_INTERN_LEVEL: 0,
|
|
56
|
+
USE_REACT_CACHE: false,
|
|
49
57
|
};
|
|
50
58
|
|
|
51
59
|
module.exports = RelayFeatureFlags;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -12,12 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import type {Observer, Sink, Subscription} from '../network/RelayObservable';
|
|
16
16
|
|
|
17
|
+
const RelayObservable = require('../network/RelayObservable');
|
|
17
18
|
const invariant = require('invariant');
|
|
18
19
|
|
|
19
|
-
import type {Observer, Sink, Subscription} from '../network/RelayObservable';
|
|
20
|
-
|
|
21
20
|
type Event<T> =
|
|
22
21
|
| {
|
|
23
22
|
kind: 'next',
|
|
@@ -42,7 +41,7 @@ class RelayReplaySubject<T> {
|
|
|
42
41
|
_events: Array<Event<T>> = [];
|
|
43
42
|
_sinks: Set<Sink<T>> = new Set();
|
|
44
43
|
_observable: RelayObservable<T>;
|
|
45
|
-
_subscription:
|
|
44
|
+
_subscription: Array<Subscription> = [];
|
|
46
45
|
|
|
47
46
|
constructor() {
|
|
48
47
|
this._observable = RelayObservable.create(sink => {
|
|
@@ -116,15 +115,16 @@ class RelayReplaySubject<T> {
|
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
subscribe(observer: Observer<T> | Sink<T>): Subscription {
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
const subscription = this._observable.subscribe(observer);
|
|
119
|
+
this._subscription.push(subscription);
|
|
120
|
+
return subscription;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
unsubscribe() {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this._subscription = null;
|
|
124
|
+
for (const subscription of this._subscription) {
|
|
125
|
+
subscription.unsubscribe();
|
|
127
126
|
}
|
|
127
|
+
this._subscription = [];
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
getObserverCount(): number {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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
|
-
* @flow strict
|
|
7
|
+
* @flow strict-local
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
* Basic types used throughout Relay.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import type {ReaderFragment, ReaderInlineDataFragment} from './ReaderNode';
|
|
20
|
+
import type {ConcreteRequest} from './RelayConcreteNode';
|
|
21
|
+
|
|
19
22
|
/**
|
|
20
23
|
* Represents any resource that must be explicitly disposed of. The most common
|
|
21
24
|
* use-case is as a return value for subscriptions, where calling `dispose()`
|
|
@@ -38,7 +41,7 @@ export type OperationType = {|
|
|
|
38
41
|
+rawResponse?: {...},
|
|
39
42
|
|};
|
|
40
43
|
|
|
41
|
-
export type VariablesOf<T: OperationType> =
|
|
44
|
+
export type VariablesOf<T: OperationType> = T['variables'];
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
47
|
* Settings for how a query response may be cached.
|
|
@@ -69,3 +72,67 @@ export type FetchPolicy =
|
|
|
69
72
|
| 'store-and-network'
|
|
70
73
|
| 'store-only';
|
|
71
74
|
export type RenderPolicy = 'full' | 'partial';
|
|
75
|
+
|
|
76
|
+
/* eslint-disable no-undef */
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Return type of graphql tag literals for all operations.
|
|
80
|
+
*/
|
|
81
|
+
declare export opaque type Operation<
|
|
82
|
+
-TVariables: Variables,
|
|
83
|
+
+TData,
|
|
84
|
+
TRawResponse,
|
|
85
|
+
>: ConcreteRequest;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Return type of graphql tag literals for queries.
|
|
89
|
+
*/
|
|
90
|
+
declare export opaque type Query<
|
|
91
|
+
-TVariables: Variables,
|
|
92
|
+
+TData,
|
|
93
|
+
TRawResponse = void,
|
|
94
|
+
>: Operation<TVariables, TData, TRawResponse>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Return type of graphql tag literals for mutations.
|
|
98
|
+
*/
|
|
99
|
+
declare export opaque type Mutation<
|
|
100
|
+
-TVariables: Variables,
|
|
101
|
+
+TData,
|
|
102
|
+
TRawResponse = void,
|
|
103
|
+
>: Operation<TVariables, TData, TRawResponse>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Return type of graphql tag literals for subscriptions.
|
|
107
|
+
*
|
|
108
|
+
* NOTE: Using the GraphQL prefix here because of a naming conflict with
|
|
109
|
+
* `RelayObservable`'s `Subscription` type.
|
|
110
|
+
*/
|
|
111
|
+
declare export opaque type GraphQLSubscription<
|
|
112
|
+
-TVariables: Variables,
|
|
113
|
+
+TData,
|
|
114
|
+
TRawResponse = void,
|
|
115
|
+
>: Operation<TVariables, TData, TRawResponse>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Return type of graphql tag literals for `@inline` fragments.
|
|
119
|
+
*/
|
|
120
|
+
declare export opaque type InlineFragment<
|
|
121
|
+
TFragmentType,
|
|
122
|
+
+TData,
|
|
123
|
+
>: ReaderInlineDataFragment;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Return type of graphql tag literals for fragments, except `@inline`
|
|
127
|
+
* fragments.
|
|
128
|
+
*/
|
|
129
|
+
declare export opaque type Fragment<TFragmentType, +TData>: ReaderFragment;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Return type of graphql tag literals for `@refetchable` fragments.
|
|
133
|
+
*/
|
|
134
|
+
declare export opaque type RefetchableFragment<
|
|
135
|
+
TFragmentType,
|
|
136
|
+
+TData,
|
|
137
|
+
-TVariables: Variables,
|
|
138
|
+
>: Fragment<TFragmentType, TData>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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
|
+
const internTable = new Map();
|
|
16
|
+
let nextIndex = 1;
|
|
17
|
+
const digits = initDigitTable();
|
|
18
|
+
|
|
19
|
+
// Character used as the prefix for interned strings. The specific character is
|
|
20
|
+
// chosen to reduce the likelihood that non-interned input strings need to be
|
|
21
|
+
// escaped (choosing eg a-Z would increase the likelihood we need to escape)
|
|
22
|
+
const INTERN_PREFIX = '\t';
|
|
23
|
+
// Character used as the prefix of escaped strings. As above, this is also
|
|
24
|
+
// chosen to be unlikely in normal input strings.
|
|
25
|
+
const ESCAPE_PREFIX = '\v';
|
|
26
|
+
|
|
27
|
+
function initDigitTable() {
|
|
28
|
+
// disable lint because digits isn't defined when this function is called
|
|
29
|
+
// eslint-disable-next-line no-shadow
|
|
30
|
+
const digits = new Set();
|
|
31
|
+
for (let i = 0; i < 10; ++i) {
|
|
32
|
+
digits.add(i.toString());
|
|
33
|
+
}
|
|
34
|
+
return digits;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Escape a string so that it cannot conflict with an interned string
|
|
38
|
+
function escape(str: string): string {
|
|
39
|
+
if (
|
|
40
|
+
// "\t<digit>..." -> "\v\t<digit>..."
|
|
41
|
+
(str[0] === INTERN_PREFIX && digits.has(str[1])) ||
|
|
42
|
+
// "\v..." -> "\v\v..."
|
|
43
|
+
str[0] === ESCAPE_PREFIX
|
|
44
|
+
) {
|
|
45
|
+
return ESCAPE_PREFIX + str;
|
|
46
|
+
}
|
|
47
|
+
return str;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Interns the input string if its length equals or exceeds the given `limit`,
|
|
51
|
+
// returning a shorter replacement string that is uniquely associated with the
|
|
52
|
+
// input: multiple calls to intern() for the equivalent input strings (and limit)
|
|
53
|
+
// will always return the exact same string.
|
|
54
|
+
// Strings shorter than the limit are not interned but are escaped if they
|
|
55
|
+
// could conflict with interned strings.
|
|
56
|
+
function intern(str: string, limit: ?number): string {
|
|
57
|
+
if (limit == null || str.length < limit) {
|
|
58
|
+
return escape(str);
|
|
59
|
+
}
|
|
60
|
+
let internedString = internTable.get(str);
|
|
61
|
+
if (internedString != null) {
|
|
62
|
+
return internedString;
|
|
63
|
+
}
|
|
64
|
+
internedString = INTERN_PREFIX + nextIndex++;
|
|
65
|
+
internTable.set(str, internedString);
|
|
66
|
+
return internedString;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = {intern};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
|
|
14
14
|
'use strict';
|
|
15
15
|
|
|
16
|
+
import type {JSResourceReference} from 'JSResourceReference';
|
|
17
|
+
import type {NormalizationSplitOperation} from './NormalizationNode';
|
|
18
|
+
|
|
16
19
|
const {
|
|
17
20
|
getModuleComponentKey,
|
|
18
21
|
getModuleOperationKey,
|
|
19
22
|
} = require('../store/RelayStoreUtils');
|
|
20
23
|
|
|
21
|
-
import type {NormalizationSplitOperation} from './NormalizationNode';
|
|
22
|
-
import type {JSResourceReference} from 'JSResourceReference';
|
|
23
|
-
|
|
24
24
|
export opaque type Local3DPayload<
|
|
25
25
|
+DocumentName: string,
|
|
26
26
|
+Response: {...},
|
package/util/deepFreeze.js.flow
CHANGED
package/util/generateID.js.flow
CHANGED