relay-runtime 21.0.0 → 21.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.
- package/experimental.d.ts +34 -0
- package/experimental.js +1 -1
- package/experimental.js.flow +4 -4
- package/handlers/RelayDefaultHandlerProvider.d.ts +12 -0
- package/handlers/connection/ConnectionHandler.d.ts +51 -0
- package/handlers/connection/ConnectionInterface.d.ts +40 -0
- package/handlers/connection/MutationHandlers.d.ts +17 -0
- package/index.d.ts +274 -0
- package/index.js +1 -1
- package/llm-docs/api-reference/relay-runtime/fetch-query.mdx +5 -0
- package/llm-docs/getting-started/compiler.mdx +19 -3
- package/llm-docs/getting-started/quick-start.mdx +15 -12
- package/llm-docs/guides/codemods.mdx +14 -1
- package/multi-actor-environment/ActorIdentifier.d.ts +17 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +9 -9
- package/multi-actor-environment/MultiActorEnvironment.d.ts +123 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +22 -18
- package/multi-actor-environment/MultiActorEnvironmentTypes.d.ts +225 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +3 -3
- package/multi-actor-environment/index.d.ts +14 -0
- package/multi-actor-environment.d.ts +8 -0
- package/mutations/RelayDeclarativeMutationConfig.d.ts +70 -0
- package/mutations/applyOptimisticMutation.d.ts +25 -0
- package/mutations/commitLocalUpdate.d.ts +10 -0
- package/mutations/commitMutation.d.ts +48 -0
- package/mutations/commitMutation.js.flow +1 -1
- package/network/RelayNetwork.d.ts +12 -0
- package/network/RelayNetworkTypes.d.ts +145 -0
- package/network/RelayNetworkTypes.js.flow +15 -15
- package/network/RelayObservable.d.ts +197 -0
- package/network/RelayObservable.js.flow +21 -21
- package/network/RelayQueryResponseCache.d.ts +16 -0
- package/package.json +1 -1
- package/query/GraphQLTag.d.ts +45 -0
- package/query/fetchQuery.d.ts +21 -0
- package/query/fetchQueryInternal.d.ts +26 -0
- package/query/fetchQueryInternal.js.flow +4 -4
- package/query/fetchQuery_DEPRECATED.d.ts +17 -0
- package/store/ClientID.d.ts +14 -0
- package/store/DataChecker.js.flow +8 -6
- package/store/NormalizationEngine.js.flow +4 -1
- package/store/OperationExecutor.d.ts +51 -0
- package/store/OperationExecutor.js.flow +33 -30
- package/store/RelayModernEnvironment.d.ts +97 -0
- package/store/RelayModernEnvironment.js.flow +21 -21
- package/store/RelayModernOperationDescriptor.d.ts +28 -0
- package/store/RelayModernRecord.d.ts +92 -0
- package/store/RelayModernSelector.d.ts +123 -0
- package/store/RelayModernStore.d.ts +57 -0
- package/store/RelayOperationTracker.d.ts +29 -0
- package/store/RelayPublishQueue.js.flow +8 -8
- package/store/RelayRecordSource.d.ts +26 -0
- package/store/RelayRecordState.d.ts +28 -0
- package/store/RelayResponseNormalizer.d.ts +28 -0
- package/store/RelayResponseNormalizer.js.flow +8 -8
- package/store/RelayStoreTypes.d.ts +1327 -0
- package/store/RelayStoreTypes.js.flow +284 -280
- package/store/RelayStoreUtils.d.ts +86 -0
- package/store/RelayStoreUtils.js.flow +2 -2
- package/store/ResolverFragments.d.ts +43 -0
- package/store/ResolverFragments.js.flow +14 -6
- package/store/StoreInspector.js.flow +2 -2
- package/store/ViewerPattern.d.ts +11 -0
- package/store/createFragmentSpecResolver.d.ts +16 -0
- package/store/defaultGetDataID.js.flow +1 -1
- package/store/isRelayModernEnvironment.d.ts +8 -0
- package/store/live-resolvers/LiveResolverCache.js.flow +1 -1
- package/store/live-resolvers/resolverDataInjector.d.ts +27 -0
- package/store/observeFragmentExperimental.d.ts +46 -0
- package/store/observeFragmentExperimental.js.flow +1 -1
- package/store/observeQueryExperimental.d.ts +30 -0
- package/store/readInlineData.d.ts +19 -0
- package/store/readInlineData.js.flow +1 -1
- package/store/waitForFragmentExperimental.d.ts +49 -0
- package/subscription/requestSubscription.d.ts +27 -0
- package/subscription/requestSubscription.js.flow +3 -3
- package/util/JSResourceTypes.flow.js.flow +4 -4
- package/util/NormalizationNode.d.ts +235 -0
- package/util/NormalizationNode.js.flow +124 -122
- package/util/ReaderNode.d.ts +264 -0
- package/util/ReaderNode.js.flow +152 -149
- package/util/RelayConcreteNode.d.ts +120 -0
- package/util/RelayConcreteNode.js.flow +31 -31
- package/util/RelayError.d.ts +13 -0
- package/util/RelayFeatureFlags.d.ts +40 -0
- package/util/RelayProfiler.d.ts +121 -0
- package/util/RelayReplaySubject.d.ts +25 -0
- package/util/RelayRuntimeTypes.d.ts +59 -0
- package/util/RelayRuntimeTypes.js.flow +33 -30
- package/util/createPayloadFor3DField.d.ts +17 -0
- package/util/createPayloadFor3DField.js.flow +4 -4
- package/util/deepFreeze.d.ts +8 -0
- package/util/getFragmentIdentifier.d.ts +10 -0
- package/util/getPaginationMetadata.d.ts +20 -0
- package/util/getPaginationVariables.d.ts +20 -0
- package/util/getPendingOperationsForFragment.d.ts +18 -0
- package/util/getRefetchMetadata.d.ts +19 -0
- package/util/getRelayHandleKey.d.ts +8 -0
- package/util/getRequestIdentifier.d.ts +17 -0
- package/util/getValueAtPath.d.ts +8 -0
- package/util/handlePotentialSnapshotErrors.d.ts +14 -0
- package/util/isEmptyObject.js.flow +1 -1
- package/util/isPromise.d.ts +8 -0
- package/util/isScalarAndEqual.d.ts +8 -0
- package/util/recycleNodesInto.d.ts +8 -0
- package/util/stableCopy.d.ts +8 -0
- package/util/withProvidedVariables.d.ts +19 -0
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
|
|
8
|
+
import { HandlerProvider } from '../handlers/RelayDefaultHandlerProvider';
|
|
9
|
+
import { MutationParameters } from '../mutations/commitMutation';
|
|
10
|
+
import {GraphQLResponse, Network, PayloadData} from '../network/RelayNetworkTypes';
|
|
11
|
+
import { RelayObservable as Observable } from '../network/RelayObservable';
|
|
12
|
+
import { TaskScheduler } from '../store/OperationExecutor';
|
|
13
|
+
import { GetDataID } from '../store/RelayResponseNormalizer';
|
|
14
|
+
import {
|
|
15
|
+
ExecuteMutationConfig,
|
|
16
|
+
LogFunction,
|
|
17
|
+
MissingFieldHandler,
|
|
18
|
+
OperationAvailability,
|
|
19
|
+
OperationDescriptor,
|
|
20
|
+
OperationLoader,
|
|
21
|
+
OptimisticResponseConfig,
|
|
22
|
+
OptimisticUpdateFunction,
|
|
23
|
+
RelayFieldLogger,
|
|
24
|
+
SelectorStoreUpdater,
|
|
25
|
+
SingularReaderSelector,
|
|
26
|
+
Snapshot,
|
|
27
|
+
Store,
|
|
28
|
+
StoreUpdater,
|
|
29
|
+
} from '../store/RelayStoreTypes';
|
|
30
|
+
import {Disposable, RenderPolicy} from '../util/RelayRuntimeTypes';
|
|
31
|
+
import { ActorIdentifier } from './ActorIdentifier';
|
|
32
|
+
import {
|
|
33
|
+
ActorEnvironment,
|
|
34
|
+
MultiActorEnvironment as IMultiActorEnvironment,
|
|
35
|
+
MultiActorStoreUpdater,
|
|
36
|
+
} from './MultiActorEnvironmentTypes';
|
|
37
|
+
|
|
38
|
+
export type MultiActorEnvironmentConfig = Readonly<{
|
|
39
|
+
createConfigNameForActor?: ((actorIdentifier: ActorIdentifier) => string) | null;
|
|
40
|
+
createNetworkForActor: (actorIdentifier: ActorIdentifier) => Network;
|
|
41
|
+
createStoreForActor?: ((actorIdentifier: ActorIdentifier) => Store) | null;
|
|
42
|
+
defaultRenderPolicy?: RenderPolicy | null;
|
|
43
|
+
getDataID?: GetDataID;
|
|
44
|
+
handlerProvider?: HandlerProvider;
|
|
45
|
+
isServer?: boolean | null;
|
|
46
|
+
logFn?: LogFunction | null;
|
|
47
|
+
missingFieldHandlers?: readonly MissingFieldHandler[] | null;
|
|
48
|
+
operationLoader?: OperationLoader | null;
|
|
49
|
+
relayFieldLogger?: RelayFieldLogger | null;
|
|
50
|
+
scheduler?: TaskScheduler | null;
|
|
51
|
+
shouldProcessClientComponents?: boolean | null;
|
|
52
|
+
treatMissingFieldsAsNull?: boolean;
|
|
53
|
+
}>;
|
|
54
|
+
|
|
55
|
+
export class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
56
|
+
constructor(config: MultiActorEnvironmentConfig);
|
|
57
|
+
|
|
58
|
+
forActor(actorIdentifier: string): ActorEnvironment;
|
|
59
|
+
|
|
60
|
+
check(actorEnvironment: ActorEnvironment, operation: OperationDescriptor): OperationAvailability;
|
|
61
|
+
|
|
62
|
+
subscribe(
|
|
63
|
+
actorEnvironment: ActorEnvironment,
|
|
64
|
+
snapshot: Snapshot,
|
|
65
|
+
callback: (snapshot: Snapshot) => void,
|
|
66
|
+
): Disposable;
|
|
67
|
+
|
|
68
|
+
retain(actorEnvironment: ActorEnvironment, operation: OperationDescriptor): Disposable;
|
|
69
|
+
|
|
70
|
+
applyUpdate(actorEnvironment: ActorEnvironment, optimisticUpdate: OptimisticUpdateFunction): Disposable;
|
|
71
|
+
|
|
72
|
+
revertUpdate(actorEnvironment: ActorEnvironment, update: OptimisticUpdateFunction): void;
|
|
73
|
+
|
|
74
|
+
replaceUpdate(
|
|
75
|
+
actorEnvironment: ActorEnvironment,
|
|
76
|
+
update: OptimisticUpdateFunction,
|
|
77
|
+
replacement: OptimisticUpdateFunction,
|
|
78
|
+
): void;
|
|
79
|
+
|
|
80
|
+
applyMutation(
|
|
81
|
+
actorEnvironment: ActorEnvironment,
|
|
82
|
+
optimisticConfig: OptimisticResponseConfig<MutationParameters>,
|
|
83
|
+
): Disposable;
|
|
84
|
+
|
|
85
|
+
commitUpdate(actorEnvironment: ActorEnvironment, updater: StoreUpdater): void;
|
|
86
|
+
|
|
87
|
+
commitMultiActorUpdate(updater: MultiActorStoreUpdater): void;
|
|
88
|
+
|
|
89
|
+
commitPayload(
|
|
90
|
+
actorEnvironment: ActorEnvironment,
|
|
91
|
+
operationDescriptor: OperationDescriptor,
|
|
92
|
+
payload: PayloadData,
|
|
93
|
+
): void;
|
|
94
|
+
|
|
95
|
+
lookup(actorEnvironment: ActorEnvironment, selector: SingularReaderSelector): Snapshot;
|
|
96
|
+
|
|
97
|
+
execute(
|
|
98
|
+
actorEnvironment: ActorEnvironment,
|
|
99
|
+
config: { operation: OperationDescriptor },
|
|
100
|
+
): Observable<GraphQLResponse>;
|
|
101
|
+
|
|
102
|
+
executeSubscription(
|
|
103
|
+
actorEnvironment: ActorEnvironment,
|
|
104
|
+
config: {
|
|
105
|
+
operation: OperationDescriptor;
|
|
106
|
+
updater?: SelectorStoreUpdater<MutationParameters['response']> | null | undefined;
|
|
107
|
+
},
|
|
108
|
+
): Observable<GraphQLResponse>;
|
|
109
|
+
|
|
110
|
+
executeMutation(
|
|
111
|
+
actorEnvironment: ActorEnvironment,
|
|
112
|
+
config: ExecuteMutationConfig<MutationParameters>,
|
|
113
|
+
): Observable<GraphQLResponse>;
|
|
114
|
+
|
|
115
|
+
executeWithSource(
|
|
116
|
+
actorEnvironment: ActorEnvironment,
|
|
117
|
+
arg: { operation: OperationDescriptor; source: Observable<GraphQLResponse> },
|
|
118
|
+
): Observable<GraphQLResponse>;
|
|
119
|
+
|
|
120
|
+
isRequestActive(actorEnvironment: ActorEnvironment, requestIdentifier: string): boolean;
|
|
121
|
+
|
|
122
|
+
isServer(): boolean;
|
|
123
|
+
}
|
|
@@ -75,24 +75,28 @@ export type MultiActorEnvironmentConfig = Readonly<{
|
|
|
75
75
|
}>;
|
|
76
76
|
|
|
77
77
|
class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
readonly _actorEnvironments: Map<ActorIdentifier, IActorEnvironment>;
|
|
79
|
+
readonly _createConfigNameForActor: ?(
|
|
80
|
+
actorIdentifier: ActorIdentifier,
|
|
81
|
+
) => string;
|
|
82
|
+
readonly _createNetworkForActor: (
|
|
83
|
+
actorIdentifier: ActorIdentifier,
|
|
84
|
+
) => INetwork;
|
|
85
|
+
readonly _createStoreForActor: ?(actorIdentifier: ActorIdentifier) => Store;
|
|
86
|
+
readonly _defaultRenderPolicy: RenderPolicy;
|
|
87
|
+
readonly _getDataID: GetDataID;
|
|
88
|
+
readonly _handlerProvider: HandlerProvider;
|
|
89
|
+
readonly _isServer: boolean;
|
|
90
|
+
readonly _logFn: LogFunction;
|
|
91
|
+
readonly _missingFieldHandlers: ReadonlyArray<MissingFieldHandler>;
|
|
92
|
+
readonly _normalizeResponse: NormalizeResponseFunction;
|
|
93
|
+
readonly _operationExecutions: Map<string, ActiveState>;
|
|
94
|
+
readonly _operationLoader: ?OperationLoader;
|
|
95
|
+
readonly _relayFieldLogger: RelayFieldLogger;
|
|
96
|
+
readonly _scheduler: ?TaskScheduler;
|
|
97
|
+
readonly _shouldProcessClientComponents: ?boolean;
|
|
98
|
+
readonly _treatMissingFieldsAsNull: boolean;
|
|
99
|
+
readonly _deferDeduplicatedFields: boolean;
|
|
96
100
|
|
|
97
101
|
constructor(config: MultiActorEnvironmentConfig) {
|
|
98
102
|
this._actorEnvironments = new Map();
|
|
@@ -0,0 +1,225 @@
|
|
|
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
|
+
|
|
8
|
+
import { MutationParameters } from '../mutations/commitMutation';
|
|
9
|
+
import {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
|
|
10
|
+
import { RelayObservable } from '../network/RelayObservable';
|
|
11
|
+
import {
|
|
12
|
+
Environment as IEnvironment,
|
|
13
|
+
ExecuteMutationConfig,
|
|
14
|
+
OperationAvailability,
|
|
15
|
+
OperationDescriptor,
|
|
16
|
+
OptimisticResponseConfig,
|
|
17
|
+
OptimisticUpdateFunction,
|
|
18
|
+
RecordSourceProxy,
|
|
19
|
+
SelectorStoreUpdater,
|
|
20
|
+
SingularReaderSelector,
|
|
21
|
+
Snapshot,
|
|
22
|
+
StoreUpdater,
|
|
23
|
+
} from '../store/RelayStoreTypes';
|
|
24
|
+
import { Disposable } from '../util/RelayRuntimeTypes';
|
|
25
|
+
import { ActorIdentifier } from './ActorIdentifier';
|
|
26
|
+
|
|
27
|
+
export type MultiActorStoreUpdater = (
|
|
28
|
+
actorIdentifier: ActorIdentifier,
|
|
29
|
+
environment: ActorEnvironment,
|
|
30
|
+
store: RecordSourceProxy,
|
|
31
|
+
) => void;
|
|
32
|
+
|
|
33
|
+
export interface ActorEnvironment extends IEnvironment {
|
|
34
|
+
/**
|
|
35
|
+
* Reference to the main MultActorEnvironment that handles
|
|
36
|
+
* the network execution/and responsible for network integration
|
|
37
|
+
*/
|
|
38
|
+
readonly multActorEnvironment: MultiActorEnvironment;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Identifier of the actor for the current active environment
|
|
42
|
+
*/
|
|
43
|
+
readonly actorIdentifier: ActorIdentifier;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Optional. A human-readable identifier of the environment.
|
|
47
|
+
* This value should be visible in the dev tools.
|
|
48
|
+
*/
|
|
49
|
+
readonly configName: string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Interface for the main (or parent) multi-actor environment that contains
|
|
54
|
+
* the map of individual actor-specific sub-environments. These sub-environments
|
|
55
|
+
* implement the Relay IEnvironment interface.
|
|
56
|
+
*/
|
|
57
|
+
export interface MultiActorEnvironment {
|
|
58
|
+
/**
|
|
59
|
+
* A factory of actor-specific environments.
|
|
60
|
+
*/
|
|
61
|
+
forActor(actorIdentifier: ActorIdentifier): ActorEnvironment;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Determine if the operation can be resolved with data in the store (i.e. no
|
|
65
|
+
* fields are missing).
|
|
66
|
+
*
|
|
67
|
+
* Note that this operation effectively "executes" the selector against the
|
|
68
|
+
* cache and therefore takes time proportional to the size/complexity of the
|
|
69
|
+
* selector.
|
|
70
|
+
*/
|
|
71
|
+
check(actorEnvironment: ActorEnvironment, operation: OperationDescriptor): OperationAvailability;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Subscribe to changes to the results of a selector. The callback is called
|
|
75
|
+
* when data has been committed to the store that would cause the results of
|
|
76
|
+
* the snapshot's selector to change.
|
|
77
|
+
*/
|
|
78
|
+
subscribe(
|
|
79
|
+
actorEnvironment: ActorEnvironment,
|
|
80
|
+
snapshot: Snapshot,
|
|
81
|
+
callback: (snapshot: Snapshot) => void,
|
|
82
|
+
): Disposable;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Ensure that all the records necessary to fulfill the given selector are
|
|
86
|
+
* retained in-memory. The records will not be eligible for garbage collection
|
|
87
|
+
* until the returned reference is disposed.
|
|
88
|
+
*/
|
|
89
|
+
retain(actorEnvironment: ActorEnvironment, operation: OperationDescriptor): Disposable;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Apply an optimistic update to the environment. The mutation can be reverted
|
|
93
|
+
* by calling `dispose()` on the returned value.
|
|
94
|
+
*/
|
|
95
|
+
applyUpdate(actorEnvironment: ActorEnvironment, optimisticUpdate: OptimisticUpdateFunction): Disposable;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Revert updates for the `update` function.
|
|
99
|
+
*/
|
|
100
|
+
revertUpdate(actorEnvironment: ActorEnvironment, update: OptimisticUpdateFunction): void;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Revert updates for the `update` function, and apply the `replacement` update.
|
|
104
|
+
*/
|
|
105
|
+
replaceUpdate(
|
|
106
|
+
actorEnvironment: ActorEnvironment,
|
|
107
|
+
update: OptimisticUpdateFunction,
|
|
108
|
+
replacement: OptimisticUpdateFunction,
|
|
109
|
+
): void;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Apply an optimistic mutation response and/or updater. The mutation can be
|
|
113
|
+
* reverted by calling `dispose()` on the returned value.
|
|
114
|
+
*/
|
|
115
|
+
applyMutation(
|
|
116
|
+
actorEnvironment: ActorEnvironment,
|
|
117
|
+
optimisticConfig: OptimisticResponseConfig<MutationParameters>,
|
|
118
|
+
): Disposable;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Commit an updater to the environment. This mutation cannot be reverted and
|
|
122
|
+
* should therefore not be used for optimistic updates. This is mainly
|
|
123
|
+
* intended for updating fields from client schema extensions.
|
|
124
|
+
*/
|
|
125
|
+
commitUpdate(actorEnvironment: ActorEnvironment, updater: StoreUpdater): void;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Commit store updates for each actor-specific environment known to MultActorEnvironment
|
|
129
|
+
*/
|
|
130
|
+
commitMultiActorUpdate(updater: MultiActorStoreUpdater): void;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Commit a payload to the environment using the given operation selector.
|
|
134
|
+
*/
|
|
135
|
+
commitPayload(
|
|
136
|
+
actorEnvironment: ActorEnvironment,
|
|
137
|
+
operationDescriptor: OperationDescriptor,
|
|
138
|
+
payload: PayloadData,
|
|
139
|
+
): void;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Read the results of a selector from in-memory records in the store.
|
|
143
|
+
*/
|
|
144
|
+
lookup(actorEnvironment: ActorEnvironment, selector: SingularReaderSelector): Snapshot;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Send a query to the server with Observer semantics: one or more
|
|
148
|
+
* responses may be returned (via `next`) over time followed by either
|
|
149
|
+
* the request completing (`completed`) or an error (`error`).
|
|
150
|
+
*
|
|
151
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
152
|
+
* the result is subscribed to: environment.execute({...}).subscribe({...}).
|
|
153
|
+
*/
|
|
154
|
+
execute(
|
|
155
|
+
actorEnvironment: ActorEnvironment,
|
|
156
|
+
config: {
|
|
157
|
+
operation: OperationDescriptor;
|
|
158
|
+
},
|
|
159
|
+
): RelayObservable<GraphQLResponse>;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Send a subscription to the server with Observer semantics: one or more
|
|
163
|
+
* responses may be returned (via `next`) over time followed by either
|
|
164
|
+
* the request completing (`completed`) or an error (`error`).
|
|
165
|
+
*
|
|
166
|
+
* Networks/servers that support subscriptions may choose to hold the
|
|
167
|
+
* subscription open indefinitely such that `complete` is not called.
|
|
168
|
+
*
|
|
169
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
170
|
+
* the result is subscribed to: environment.executeSubscription({...}).subscribe({...}).
|
|
171
|
+
*/
|
|
172
|
+
executeSubscription(
|
|
173
|
+
actorEnvironment: ActorEnvironment,
|
|
174
|
+
config: {
|
|
175
|
+
operation: OperationDescriptor;
|
|
176
|
+
updater?: SelectorStoreUpdater<MutationParameters['response']> | null;
|
|
177
|
+
},
|
|
178
|
+
): RelayObservable<GraphQLResponse>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
182
|
+
* provided Mutation operation, the result of which is then normalized and
|
|
183
|
+
* committed to the publish queue along with an optional optimistic response
|
|
184
|
+
* or updater.
|
|
185
|
+
*
|
|
186
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
187
|
+
* the result is subscribed to:
|
|
188
|
+
* environment.executeMutation({...}).subscribe({...}).
|
|
189
|
+
*/
|
|
190
|
+
executeMutation(
|
|
191
|
+
actorEnvironment: ActorEnvironment,
|
|
192
|
+
config: ExecuteMutationConfig<MutationParameters>,
|
|
193
|
+
): RelayObservable<GraphQLResponse>;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
197
|
+
* provided Query or Subscription operation responses, the result of which is
|
|
198
|
+
* then normalized and committed to the publish queue.
|
|
199
|
+
*
|
|
200
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
201
|
+
* the result is subscribed to:
|
|
202
|
+
* environment.executeWithSource({...}).subscribe({...}).
|
|
203
|
+
*/
|
|
204
|
+
executeWithSource(
|
|
205
|
+
actorEnvironment: ActorEnvironment,
|
|
206
|
+
arg: {
|
|
207
|
+
operation: OperationDescriptor;
|
|
208
|
+
source: RelayObservable<GraphQLResponse>;
|
|
209
|
+
},
|
|
210
|
+
): RelayObservable<GraphQLResponse>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Returns true if a request is currently "active", meaning it's currently
|
|
214
|
+
* actively receiving payloads or downloading modules, and has not received
|
|
215
|
+
* a final payload yet. Note that a request might still be pending (or "in flight")
|
|
216
|
+
* without actively receiving payload, for example a live query or an
|
|
217
|
+
* active GraphQL subscription
|
|
218
|
+
*/
|
|
219
|
+
isRequestActive(actorEnvironment: ActorEnvironment, requestIdentifier: string): boolean;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Returns `true` if execute in the server environment
|
|
223
|
+
*/
|
|
224
|
+
isServer(): boolean;
|
|
225
|
+
}
|
|
@@ -46,12 +46,12 @@ export interface IActorEnvironment extends IEnvironment {
|
|
|
46
46
|
* Reference to the main MultiActorEnvironment that handles
|
|
47
47
|
* the network execution/and responsible for network integration
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
readonly multiActorEnvironment: IMultiActorEnvironment;
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Identifier of the actor for the current active environment
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
readonly actorIdentifier: ActorIdentifier;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* TODO: this needs to move the the MultiActorEnvironment with different API.
|
|
@@ -62,7 +62,7 @@ export interface IActorEnvironment extends IEnvironment {
|
|
|
62
62
|
* Optional. A human-readable identifier of the environment.
|
|
63
63
|
* This value should be visible in the dev tools.
|
|
64
64
|
*/
|
|
65
|
-
|
|
65
|
+
readonly configName: ?string;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
|
|
8
|
+
export { ActorIdentifier, getActorIdentifier } from './ActorIdentifier';
|
|
9
|
+
|
|
10
|
+
export { MultiActorEnvironment } from './MultiActorEnvironment';
|
|
11
|
+
export {
|
|
12
|
+
ActorEnvironment as IActorEnvironment,
|
|
13
|
+
MultiActorEnvironment as IMultiActorEnvironment,
|
|
14
|
+
} from './MultiActorEnvironmentTypes';
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
|
|
8
|
+
import { SelectorStoreUpdater } from '../store/RelayStoreTypes';
|
|
9
|
+
import { ConcreteRequest } from '../util/RelayConcreteNode';
|
|
10
|
+
import { Variables } from '../util/RelayRuntimeTypes';
|
|
11
|
+
|
|
12
|
+
export type MutationTypes = 'RANGE_ADD' | 'RANGE_DELETE' | 'NODE_DELETE';
|
|
13
|
+
|
|
14
|
+
export type RangeOperations = 'append' | 'prepend';
|
|
15
|
+
export type RangeBehaviorsFunction = (connectionArgs: { [name: string]: unknown }) => RangeOperations;
|
|
16
|
+
export interface RangeBehaviorsObject {
|
|
17
|
+
[key: string]: RangeOperations;
|
|
18
|
+
}
|
|
19
|
+
export type RangeBehaviors = RangeBehaviorsFunction | RangeBehaviorsObject;
|
|
20
|
+
|
|
21
|
+
export interface RangeAddConfig {
|
|
22
|
+
type: 'RANGE_ADD';
|
|
23
|
+
parentName?: string | undefined;
|
|
24
|
+
parentID?: string | undefined;
|
|
25
|
+
connectionInfo?:
|
|
26
|
+
| ReadonlyArray<{
|
|
27
|
+
key: string;
|
|
28
|
+
filters?: Variables | undefined;
|
|
29
|
+
rangeBehavior: string;
|
|
30
|
+
}>
|
|
31
|
+
| undefined;
|
|
32
|
+
connectionName?: string | undefined;
|
|
33
|
+
edgeName: string;
|
|
34
|
+
rangeBehaviors?: RangeBehaviors | undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface RangeDeleteConfig {
|
|
38
|
+
type: 'RANGE_DELETE';
|
|
39
|
+
parentName?: string | undefined;
|
|
40
|
+
parentID?: string | undefined;
|
|
41
|
+
connectionKeys?:
|
|
42
|
+
| ReadonlyArray<{
|
|
43
|
+
key: string;
|
|
44
|
+
filters?: Variables | undefined;
|
|
45
|
+
}>
|
|
46
|
+
| undefined;
|
|
47
|
+
connectionName?: string | undefined;
|
|
48
|
+
deletedIDFieldName: string | readonly string[];
|
|
49
|
+
pathToConnection: readonly string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface NodeDeleteConfig {
|
|
53
|
+
type: 'NODE_DELETE';
|
|
54
|
+
parentName?: string | undefined;
|
|
55
|
+
parentID?: string | undefined;
|
|
56
|
+
connectionName?: string | undefined;
|
|
57
|
+
deletedIDFieldName: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type DeclarativeMutationConfig = RangeAddConfig | RangeDeleteConfig | NodeDeleteConfig;
|
|
61
|
+
|
|
62
|
+
export function convert(
|
|
63
|
+
configs: DeclarativeMutationConfig[],
|
|
64
|
+
request: ConcreteRequest,
|
|
65
|
+
optimisticUpdater?: SelectorStoreUpdater,
|
|
66
|
+
updater?: SelectorStoreUpdater,
|
|
67
|
+
): {
|
|
68
|
+
optimisticUpdater: SelectorStoreUpdater;
|
|
69
|
+
updater: SelectorStoreUpdater;
|
|
70
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
|
|
8
|
+
import { GraphQLTaggedNode } from '../query/GraphQLTag';
|
|
9
|
+
import {Environment, SelectorStoreUpdater} from '../store/RelayStoreTypes';
|
|
10
|
+
import {Disposable, Variables} from '../util/RelayRuntimeTypes';
|
|
11
|
+
import { DeclarativeMutationConfig } from './RelayDeclarativeMutationConfig';
|
|
12
|
+
|
|
13
|
+
export interface OptimisticMutationConfig {
|
|
14
|
+
configs?: readonly DeclarativeMutationConfig[] | null | undefined;
|
|
15
|
+
mutation: GraphQLTaggedNode;
|
|
16
|
+
variables: Variables;
|
|
17
|
+
optimisticUpdater?: SelectorStoreUpdater | null | undefined;
|
|
18
|
+
optimisticResponse?: object | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Higher-level helper function to execute a mutation against a specific
|
|
23
|
+
* environment.
|
|
24
|
+
*/
|
|
25
|
+
export function applyOptimisticMutation(environment: Environment, config: OptimisticMutationConfig): Disposable;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
|
|
8
|
+
import {Environment, SelectorStoreUpdater} from '../store/RelayStoreTypes';
|
|
9
|
+
|
|
10
|
+
export function commitLocalUpdate(environment: Environment, updater: SelectorStoreUpdater): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
|
|
8
|
+
import {PayloadError, UploadableMap} from '../network/RelayNetworkTypes';
|
|
9
|
+
import { GraphQLTaggedNode } from '../query/GraphQLTag';
|
|
10
|
+
import {Environment, SelectorStoreUpdater} from '../store/RelayStoreTypes';
|
|
11
|
+
import {CacheConfig, Disposable} from '../util/RelayRuntimeTypes';
|
|
12
|
+
import { DeclarativeMutationConfig } from './RelayDeclarativeMutationConfig';
|
|
13
|
+
|
|
14
|
+
export interface MutationParameters {
|
|
15
|
+
readonly response: Record<string, unknown>;
|
|
16
|
+
readonly variables: Record<string, unknown>;
|
|
17
|
+
readonly rawResponse?: Record<string, unknown> | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MutationConfig<TOperation extends MutationParameters> {
|
|
21
|
+
configs?: DeclarativeMutationConfig[] | undefined;
|
|
22
|
+
cacheConfig?: CacheConfig | undefined;
|
|
23
|
+
mutation: GraphQLTaggedNode;
|
|
24
|
+
onError?: ((error: Error) => void) | null | undefined;
|
|
25
|
+
onCompleted?:
|
|
26
|
+
| ((response: TOperation['response'], errors: readonly PayloadError[] | null | undefined) => void)
|
|
27
|
+
| null
|
|
28
|
+
| undefined;
|
|
29
|
+
onUnsubscribe?: (() => void | null | undefined) | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* An object whose type matches the raw response type of the mutation. Make sure you decorate
|
|
32
|
+
* your mutation with `@raw_response_type` if you are using this field.
|
|
33
|
+
*/
|
|
34
|
+
optimisticResponse?: (TOperation['rawResponse'] extends Record<string, unknown> ? TOperation['rawResponse'] : never) | undefined;
|
|
35
|
+
optimisticUpdater?: SelectorStoreUpdater<TOperation['response']> | null | undefined;
|
|
36
|
+
updater?: SelectorStoreUpdater<TOperation['response']> | null | undefined;
|
|
37
|
+
uploadables?: UploadableMap | null | undefined;
|
|
38
|
+
variables: TOperation['variables'];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Higher-level helper function to execute a mutation against a specific
|
|
43
|
+
* environment.
|
|
44
|
+
*/
|
|
45
|
+
export function commitMutation<TOperation extends MutationParameters = MutationParameters>(
|
|
46
|
+
environment: Environment,
|
|
47
|
+
config: MutationConfig<TOperation>,
|
|
48
|
+
): Disposable;
|
|
@@ -49,7 +49,7 @@ export type MutationConfig<TMutation extends MutationParameters> = Readonly<{
|
|
|
49
49
|
onNext?: ?() => void,
|
|
50
50
|
onUnsubscribe?: ?() => void,
|
|
51
51
|
optimisticResponse?: {
|
|
52
|
-
|
|
52
|
+
readonly rawResponse?: {...},
|
|
53
53
|
...TMutation,
|
|
54
54
|
...
|
|
55
55
|
}['rawResponse'],
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
|
|
8
|
+
import {FetchFunction, Network, SubscribeFunction} from './RelayNetworkTypes';
|
|
9
|
+
|
|
10
|
+
export const RelayNetwork: {
|
|
11
|
+
create(fetchFn: FetchFunction, subscribeFn?: SubscribeFunction): Network;
|
|
12
|
+
};
|