relay-runtime 20.1.1 → 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 +11 -11
- package/handlers/RelayDefaultHandlerProvider.d.ts +12 -0
- package/handlers/connection/ConnectionHandler.d.ts +51 -0
- package/handlers/connection/ConnectionHandler.js.flow +5 -5
- package/handlers/connection/ConnectionInterface.d.ts +40 -0
- package/handlers/connection/ConnectionInterface.js.flow +1 -1
- package/handlers/connection/MutationHandlers.d.ts +17 -0
- package/index.d.ts +274 -0
- package/index.js +1 -1
- package/index.js.flow +125 -62
- package/lib/experimental.js +3 -3
- package/lib/index.js +105 -57
- package/lib/multi-actor-environment/ActorIdentifier.js +2 -2
- package/lib/multi-actor-environment/MultiActorEnvironment.js +3 -1
- package/lib/mutations/commitMutation.js +8 -8
- package/lib/mutations/validateMutation.js +4 -4
- package/lib/query/GraphQLTag.js +3 -3
- package/lib/query/fetchQuery.js +15 -3
- package/lib/store/DataChecker.js +38 -4
- package/lib/store/NormalizationEngine.js +373 -0
- package/lib/store/OperationExecutor.js +172 -113
- package/lib/store/RelayConcreteVariables.js +1 -1
- package/lib/store/RelayErrorTrie.js +2 -2
- package/lib/store/RelayExperimentalGraphResponseTransform.js +8 -8
- package/lib/store/RelayModernEnvironment.js +26 -19
- package/lib/store/RelayModernRecord.js +18 -8
- package/lib/store/RelayModernSelector.js +9 -9
- package/lib/store/RelayModernStore.js +152 -43
- package/lib/store/RelayPublishQueue.js +1 -1
- package/lib/store/RelayReader.js +76 -38
- package/lib/store/RelayRecordSource.js +6 -0
- package/lib/store/RelayReferenceMarker.js +2 -1
- package/lib/store/RelayResponseNormalizer.js +88 -55
- package/lib/store/RelayStoreSubscriptions.js +34 -10
- package/lib/store/RelayStoreUtils.js +8 -1
- package/lib/store/ResolverFragments.js +2 -2
- package/lib/store/live-resolvers/LiveResolverCache.js +25 -9
- package/lib/store/observeFragmentExperimental.js +17 -1
- package/lib/store/observeQueryExperimental.js +2 -2
- package/lib/subscription/requestSubscription.js +3 -3
- package/lib/util/RelayError.js +3 -0
- package/lib/util/RelayFeatureFlags.js +6 -2
- package/lib/util/RelayReplaySubject.js +4 -4
- package/lib/util/handlePotentialSnapshotErrors.js +2 -2
- package/lib/util/stableCopy.js +2 -2
- package/llm-docs/api-reference/entrypoint-apis/entrypoint-container.mdx +38 -0
- package/llm-docs/api-reference/entrypoint-apis/load-entrypoint.mdx +77 -0
- package/llm-docs/api-reference/entrypoint-apis/use-entrypoint-loader.mdx +99 -0
- package/llm-docs/api-reference/graphql/graphql-directives.mdx +378 -0
- package/llm-docs/api-reference/hooks/_use-lazy-load-query-extra.mdx +16 -0
- package/llm-docs/api-reference/hooks/load-query.mdx +84 -0
- package/llm-docs/api-reference/hooks/relay-environment-provider.mdx +78 -0
- package/llm-docs/api-reference/hooks/use-client-query.mdx +65 -0
- package/llm-docs/api-reference/hooks/use-fragment.mdx +69 -0
- package/llm-docs/api-reference/hooks/use-lazy-load-query.mdx +62 -0
- package/llm-docs/api-reference/hooks/use-mutation.mdx +94 -0
- package/llm-docs/api-reference/hooks/use-pagination-fragment.mdx +166 -0
- package/llm-docs/api-reference/hooks/use-prefetchable-forward-pagination-fragment.mdx +134 -0
- package/llm-docs/api-reference/hooks/use-preloaded-query.mdx +84 -0
- package/llm-docs/api-reference/hooks/use-query-loader.mdx +95 -0
- package/llm-docs/api-reference/hooks/use-refetchable-fragment.mdx +122 -0
- package/llm-docs/api-reference/hooks/use-relay-environment.mdx +37 -0
- package/llm-docs/api-reference/hooks/use-subscription.mdx +66 -0
- package/llm-docs/api-reference/relay-resolvers/docblock-format.mdx +321 -0
- package/llm-docs/api-reference/relay-resolvers/runtime-functions.mdx +94 -0
- package/llm-docs/api-reference/relay-runtime/commit-mutation.mdx +65 -0
- package/llm-docs/api-reference/relay-runtime/fetch-query.mdx +118 -0
- package/llm-docs/api-reference/relay-runtime/field-logger.mdx +170 -0
- package/llm-docs/api-reference/relay-runtime/observe-fragment.mdx +92 -0
- package/llm-docs/api-reference/relay-runtime/relay-environment.mdx +53 -0
- package/llm-docs/api-reference/relay-runtime/request-subscription.mdx +54 -0
- package/llm-docs/api-reference/relay-runtime/runtime-configuration.mdx +52 -0
- package/llm-docs/api-reference/relay-runtime/store.mdx +734 -0
- package/llm-docs/api-reference/relay-runtime/wait-for-fragment-data.mdx +89 -0
- package/llm-docs/api-reference/types/CacheConfig.mdx +8 -0
- package/llm-docs/api-reference/types/Disposable.mdx +4 -0
- package/llm-docs/api-reference/types/GraphQLSubscriptionConfig.mdx +17 -0
- package/llm-docs/api-reference/types/MutationConfig.mdx +31 -0
- package/llm-docs/api-reference/types/SelectorStoreUpdater.mdx +6 -0
- package/llm-docs/api-reference/types/UploadableMap.mdx +3 -0
- package/llm-docs/community/learning-resources.mdx +64 -0
- package/llm-docs/debugging/declarative-mutation-directives.mdx +34 -0
- package/llm-docs/debugging/disallowed-id-types-error.mdx +43 -0
- package/llm-docs/debugging/inconsistent-typename-error.mdx +47 -0
- package/llm-docs/debugging/relay-devtools.mdx +73 -0
- package/llm-docs/debugging/why-null.mdx +116 -0
- package/llm-docs/editor-support.mdx +55 -0
- package/llm-docs/error-reference/unknown-field.mdx +36 -0
- package/llm-docs/getting-started/babel-plugin.mdx +31 -0
- package/llm-docs/getting-started/compiler-config.mdx +25 -0
- package/llm-docs/getting-started/compiler.mdx +98 -0
- package/llm-docs/getting-started/lint-rules.mdx +87 -0
- package/llm-docs/getting-started/production.mdx +30 -0
- package/llm-docs/getting-started/quick-start.mdx +216 -0
- package/llm-docs/glossary/glossary.mdx +1040 -0
- package/llm-docs/guided-tour/list-data/advanced-pagination.mdx +157 -0
- package/llm-docs/guided-tour/list-data/connections.mdx +81 -0
- package/llm-docs/guided-tour/list-data/pagination.mdx +193 -0
- package/llm-docs/guided-tour/list-data/rendering-connections.mdx +112 -0
- package/llm-docs/guided-tour/list-data/streaming-pagination.mdx +87 -0
- package/llm-docs/guided-tour/managing-data-outside-react/retaining-queries.mdx +51 -0
- package/llm-docs/guided-tour/refetching/refetching-queries-with-different-data.mdx +337 -0
- package/llm-docs/guided-tour/refetching/refreshing-queries.mdx +350 -0
- package/llm-docs/guided-tour/rendering/environment.mdx +59 -0
- package/llm-docs/guided-tour/rendering/error-states.mdx +295 -0
- package/llm-docs/guided-tour/rendering/fragments.mdx +354 -0
- package/llm-docs/guided-tour/rendering/loading-states.mdx +245 -0
- package/llm-docs/guided-tour/rendering/queries.mdx +261 -0
- package/llm-docs/guided-tour/rendering/variables.mdx +233 -0
- package/llm-docs/guided-tour/reusing-cached-data/fetch-policies.mdx +56 -0
- package/llm-docs/guided-tour/reusing-cached-data/filling-in-missing-data.mdx +102 -0
- package/llm-docs/guided-tour/reusing-cached-data/introduction.mdx +22 -0
- package/llm-docs/guided-tour/reusing-cached-data/presence-of-data.mdx +93 -0
- package/llm-docs/guided-tour/reusing-cached-data/rendering-partially-cached-data.mdx +175 -0
- package/llm-docs/guided-tour/reusing-cached-data/staleness-of-data.mdx +116 -0
- package/llm-docs/guided-tour/updating-data/client-only-data.mdx +115 -0
- package/llm-docs/guided-tour/updating-data/graphql-mutations.mdx +334 -0
- package/llm-docs/guided-tour/updating-data/graphql-subscriptions.mdx +279 -0
- package/llm-docs/guided-tour/updating-data/imperatively-modifying-linked-fields.mdx +511 -0
- package/llm-docs/guided-tour/updating-data/imperatively-modifying-store-data-legacy.mdx +142 -0
- package/llm-docs/guided-tour/updating-data/imperatively-modifying-store-data.mdx +275 -0
- package/llm-docs/guided-tour/updating-data/introduction.mdx +25 -0
- package/llm-docs/guided-tour/updating-data/local-data-updates.mdx +71 -0
- package/llm-docs/guided-tour/updating-data/typesafe-updaters-faq.mdx +83 -0
- package/llm-docs/guided-tour/updating-data/updating-connections.mdx +592 -0
- package/llm-docs/guides/alias-directive.mdx +160 -0
- package/llm-docs/guides/catch-directive.mdx +167 -0
- package/llm-docs/guides/client-schema-extensions.mdx +208 -0
- package/llm-docs/guides/codemods.mdx +79 -0
- package/llm-docs/guides/data-driven-dependencies/client-3d.mdx +255 -0
- package/llm-docs/guides/data-driven-dependencies/configuration.mdx +127 -0
- package/llm-docs/guides/data-driven-dependencies/introduction.mdx +39 -0
- package/llm-docs/guides/data-driven-dependencies/server-3d.mdx +664 -0
- package/llm-docs/guides/document-comparison.mdx +106 -0
- package/llm-docs/guides/graphql-server-specification.mdx +453 -0
- package/llm-docs/guides/network-layer.mdx +69 -0
- package/llm-docs/guides/persisted-queries.mdx +328 -0
- package/llm-docs/guides/relay-resolvers/context.mdx +99 -0
- package/llm-docs/guides/relay-resolvers/defining-fields.mdx +151 -0
- package/llm-docs/guides/relay-resolvers/defining-types.mdx +164 -0
- package/llm-docs/guides/relay-resolvers/deprecated.mdx +27 -0
- package/llm-docs/guides/relay-resolvers/derived-fields.mdx +127 -0
- package/llm-docs/guides/relay-resolvers/descriptions.mdx +44 -0
- package/llm-docs/guides/relay-resolvers/enabling.mdx +41 -0
- package/llm-docs/guides/relay-resolvers/errors.mdx +64 -0
- package/llm-docs/guides/relay-resolvers/field-arguments.mdx +63 -0
- package/llm-docs/guides/relay-resolvers/introduction.mdx +62 -0
- package/llm-docs/guides/relay-resolvers/limitations.mdx +30 -0
- package/llm-docs/guides/relay-resolvers/live-fields.mdx +164 -0
- package/llm-docs/guides/relay-resolvers/return-types.mdx +161 -0
- package/llm-docs/guides/relay-resolvers/suspense.mdx +41 -0
- package/llm-docs/guides/required-directive.mdx +240 -0
- package/llm-docs/guides/semantic-nullability.mdx +93 -0
- package/llm-docs/guides/testing-relay-components.mdx +642 -0
- package/llm-docs/guides/testing-relay-with-preloaded-queries.mdx +160 -0
- package/llm-docs/guides/throw-on-field-error-directive.mdx +58 -0
- package/llm-docs/guides/type-emission.mdx +414 -0
- package/llm-docs/home.mdx +32 -0
- package/llm-docs/principles-and-architecture/architecture-overview.mdx +24 -0
- package/llm-docs/principles-and-architecture/compiler-architecture.mdx +106 -0
- package/llm-docs/principles-and-architecture/runtime-architecture.mdx +249 -0
- package/llm-docs/principles-and-architecture/thinking-in-graphql.mdx +309 -0
- package/llm-docs/principles-and-architecture/thinking-in-relay.mdx +104 -0
- package/llm-docs/principles-and-architecture/videos.mdx +50 -0
- package/llm-docs/tutorial/arrays-lists.mdx +126 -0
- package/llm-docs/tutorial/fragments-1.mdx +487 -0
- package/llm-docs/tutorial/graphql.mdx +172 -0
- package/llm-docs/tutorial/interfaces-polymorphism.mdx +161 -0
- package/llm-docs/tutorial/intro.mdx +58 -0
- package/llm-docs/tutorial/mutations-updates.mdx +624 -0
- package/llm-docs/tutorial/organizing-mutations-queries-and-subscriptions.mdx +13 -0
- package/llm-docs/tutorial/queries-1.mdx +267 -0
- package/llm-docs/tutorial/queries-2.mdx +389 -0
- package/llm-docs/tutorial/refetchable-fragments.mdx +352 -0
- package/multi-actor-environment/ActorIdentifier.d.ts +17 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +2 -2
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +15 -15
- package/multi-actor-environment/ActorUtils.js.flow +1 -1
- package/multi-actor-environment/MultiActorEnvironment.d.ts +123 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +32 -24
- package/multi-actor-environment/MultiActorEnvironmentTypes.d.ts +225 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +6 -6
- 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/RelayDeclarativeMutationConfig.js.flow +9 -9
- package/mutations/RelayRecordProxy.js.flow +8 -11
- package/mutations/RelayRecordSourceMutator.js.flow +4 -4
- package/mutations/RelayRecordSourceProxy.js.flow +4 -4
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +6 -6
- package/mutations/applyOptimisticMutation.d.ts +25 -0
- package/mutations/applyOptimisticMutation.js.flow +2 -2
- package/mutations/commitLocalUpdate.d.ts +10 -0
- package/mutations/commitMutation.d.ts +48 -0
- package/mutations/commitMutation.js.flow +21 -17
- package/mutations/createUpdatableProxy.js.flow +19 -19
- package/mutations/readUpdatableFragment.js.flow +3 -3
- package/mutations/readUpdatableQuery.js.flow +3 -3
- package/mutations/validateMutation.js.flow +7 -7
- package/network/RelayNetwork.d.ts +12 -0
- package/network/RelayNetworkTypes.d.ts +145 -0
- package/network/RelayNetworkTypes.js.flow +18 -18
- package/network/RelayObservable.d.ts +197 -0
- package/network/RelayObservable.js.flow +32 -30
- package/network/RelayQueryResponseCache.d.ts +16 -0
- package/network/RelayQueryResponseCache.js.flow +3 -3
- package/network/wrapNetworkWithLogObserver.js.flow +1 -1
- package/package.json +2 -1
- package/query/GraphQLTag.d.ts +45 -0
- package/query/GraphQLTag.js.flow +22 -10
- package/query/fetchQuery.d.ts +21 -0
- package/query/fetchQuery.js.flow +23 -10
- package/query/fetchQueryInternal.d.ts +26 -0
- package/query/fetchQueryInternal.js.flow +4 -4
- package/query/fetchQuery_DEPRECATED.d.ts +17 -0
- package/query/fetchQuery_DEPRECATED.js.flow +1 -1
- package/store/ClientID.d.ts +14 -0
- package/store/DataChecker.js.flow +51 -15
- package/store/NormalizationEngine.js.flow +782 -0
- package/store/OperationExecutor.d.ts +51 -0
- package/store/OperationExecutor.js.flow +204 -98
- package/store/RelayConcreteVariables.js.flow +5 -5
- package/store/RelayErrorTrie.js.flow +12 -12
- package/store/RelayExperimentalGraphResponseHandler.js.flow +3 -3
- package/store/RelayExperimentalGraphResponseTransform.js.flow +10 -10
- package/store/RelayModernEnvironment.d.ts +97 -0
- package/store/RelayModernEnvironment.js.flow +58 -43
- package/store/RelayModernFragmentSpecResolver.js.flow +1 -1
- package/store/RelayModernOperationDescriptor.d.ts +28 -0
- package/store/RelayModernOperationDescriptor.js.flow +1 -1
- package/store/RelayModernRecord.d.ts +92 -0
- package/store/RelayModernRecord.js.flow +44 -20
- package/store/RelayModernSelector.d.ts +123 -0
- package/store/RelayModernSelector.js.flow +21 -21
- package/store/RelayModernStore.d.ts +57 -0
- package/store/RelayModernStore.js.flow +219 -58
- package/store/RelayOperationTracker.d.ts +29 -0
- package/store/RelayOperationTracker.js.flow +2 -2
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +29 -20
- package/store/RelayReader.js.flow +129 -57
- package/store/RelayRecordSource.d.ts +26 -0
- package/store/RelayRecordSource.js.flow +10 -0
- package/store/RelayRecordState.d.ts +28 -0
- package/store/RelayRecordState.js.flow +1 -1
- package/store/RelayReferenceMarker.js.flow +5 -4
- package/store/RelayResponseNormalizer.d.ts +28 -0
- package/store/RelayResponseNormalizer.js.flow +130 -62
- package/store/RelayStoreSubscriptions.js.flow +52 -8
- package/store/RelayStoreTypes.d.ts +1327 -0
- package/store/RelayStoreTypes.js.flow +371 -278
- package/store/RelayStoreUtils.d.ts +86 -0
- package/store/RelayStoreUtils.js.flow +16 -8
- package/store/ResolverCache.js.flow +2 -2
- package/store/ResolverFragments.d.ts +43 -0
- package/store/ResolverFragments.js.flow +22 -14
- package/store/StoreInspector.js.flow +7 -8
- package/store/ViewerPattern.d.ts +11 -0
- package/store/cloneRelayHandleSourceField.js.flow +1 -1
- package/store/cloneRelayScalarHandleSourceField.js.flow +1 -1
- package/store/createFragmentSpecResolver.d.ts +16 -0
- package/store/createRelayContext.js.flow +1 -1
- package/store/createRelayLoggingContext.js.flow +4 -4
- package/store/defaultGetDataID.js.flow +2 -2
- package/store/isRelayModernEnvironment.d.ts +8 -0
- package/store/isRelayModernEnvironment.js.flow +4 -2
- package/store/live-resolvers/LiveResolverCache.js.flow +55 -20
- package/store/live-resolvers/LiveResolverSuspenseSentinel.js.flow +3 -3
- package/store/live-resolvers/getOutputTypeRecordIDs.js.flow +1 -1
- package/store/live-resolvers/isLiveStateValue.js.flow +2 -2
- package/store/live-resolvers/resolverDataInjector.d.ts +27 -0
- package/store/live-resolvers/resolverDataInjector.js.flow +8 -5
- package/store/observeFragmentExperimental.d.ts +46 -0
- package/store/observeFragmentExperimental.js.flow +50 -21
- package/store/observeQueryExperimental.d.ts +30 -0
- package/store/observeQueryExperimental.js.flow +5 -5
- package/store/readInlineData.d.ts +19 -0
- package/store/readInlineData.js.flow +5 -5
- package/store/waitForFragmentExperimental.d.ts +49 -0
- package/store/waitForFragmentExperimental.js.flow +3 -3
- package/subscription/requestSubscription.d.ts +27 -0
- package/subscription/requestSubscription.js.flow +10 -10
- package/util/JSResourceTypes.flow.js.flow +4 -4
- package/util/NormalizationNode.d.ts +235 -0
- package/util/NormalizationNode.js.flow +127 -123
- package/util/ReaderNode.d.ts +264 -0
- package/util/ReaderNode.js.flow +156 -151
- package/util/RelayConcreteNode.d.ts +120 -0
- package/util/RelayConcreteNode.js.flow +32 -32
- package/util/RelayError.d.ts +13 -0
- package/util/RelayError.js.flow +4 -1
- package/util/RelayFeatureFlags.d.ts +40 -0
- package/util/RelayFeatureFlags.js.flow +21 -1
- package/util/RelayProfiler.d.ts +121 -0
- package/util/RelayProfiler.js.flow +1 -1
- package/util/RelayReplaySubject.d.ts +25 -0
- package/util/RelayReplaySubject.js.flow +3 -3
- package/util/RelayRuntimeTypes.d.ts +59 -0
- package/util/RelayRuntimeTypes.js.flow +36 -33
- package/util/createPayloadFor3DField.d.ts +17 -0
- package/util/createPayloadFor3DField.js.flow +9 -5
- package/util/deepFreeze.d.ts +8 -0
- package/util/deepFreeze.js.flow +2 -2
- package/util/getFragmentIdentifier.d.ts +10 -0
- package/util/getFragmentIdentifier.js.flow +1 -1
- package/util/getPaginationMetadata.d.ts +20 -0
- package/util/getPaginationMetadata.js.flow +1 -1
- package/util/getPaginationVariables.d.ts +20 -0
- package/util/getPaginationVariables.js.flow +1 -1
- package/util/getPendingOperationsForFragment.d.ts +18 -0
- package/util/getPendingOperationsForFragment.js.flow +2 -2
- package/util/getRefetchMetadata.d.ts +19 -0
- package/util/getRefetchMetadata.js.flow +6 -5
- package/util/getRelayHandleKey.d.ts +8 -0
- package/util/getRequestIdentifier.d.ts +17 -0
- package/util/getValueAtPath.d.ts +8 -0
- package/util/getValueAtPath.js.flow +3 -3
- package/util/handlePotentialSnapshotErrors.d.ts +14 -0
- package/util/handlePotentialSnapshotErrors.js.flow +5 -5
- package/util/isEmptyObject.js.flow +1 -1
- package/util/isPromise.d.ts +8 -0
- package/util/isPromise.js.flow +2 -2
- package/util/isScalarAndEqual.d.ts +8 -0
- package/util/isScalarAndEqual.js.flow +1 -1
- package/util/recycleNodesInto.d.ts +8 -0
- package/util/recycleNodesInto.js.flow +2 -2
- package/util/registerEnvironmentWithDevTools.js.flow +1 -1
- package/util/shallowFreeze.js.flow +1 -1
- package/util/stableCopy.d.ts +8 -0
- package/util/stableCopy.js.flow +5 -5
- package/util/withProvidedVariables.d.ts +19 -0
- package/util/withProvidedVariables.js.flow +14 -10
|
@@ -55,7 +55,7 @@ const RelayModernStore = require('../store/RelayModernStore');
|
|
|
55
55
|
const RelayRecordSource = require('../store/RelayRecordSource');
|
|
56
56
|
const ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
57
57
|
|
|
58
|
-
export type MultiActorEnvironmentConfig =
|
|
58
|
+
export type MultiActorEnvironmentConfig = Readonly<{
|
|
59
59
|
createConfigNameForActor?: ?(actorIdentifier: ActorIdentifier) => string,
|
|
60
60
|
createNetworkForActor: (actorIdentifier: ActorIdentifier) => INetwork,
|
|
61
61
|
createStoreForActor?: ?(actorIdentifier: ActorIdentifier) => Store,
|
|
@@ -64,33 +64,39 @@ export type MultiActorEnvironmentConfig = $ReadOnly<{
|
|
|
64
64
|
handlerProvider?: HandlerProvider,
|
|
65
65
|
isServer?: ?boolean,
|
|
66
66
|
logFn?: ?LogFunction,
|
|
67
|
-
missingFieldHandlers?:
|
|
67
|
+
missingFieldHandlers?: ?ReadonlyArray<MissingFieldHandler>,
|
|
68
68
|
normalizeResponse?: NormalizeResponseFunction,
|
|
69
69
|
operationLoader?: ?OperationLoader,
|
|
70
70
|
relayFieldLogger?: ?RelayFieldLogger,
|
|
71
71
|
scheduler?: ?TaskScheduler,
|
|
72
72
|
shouldProcessClientComponents?: ?boolean,
|
|
73
73
|
treatMissingFieldsAsNull?: boolean,
|
|
74
|
+
deferDeduplicatedFields?: boolean,
|
|
74
75
|
}>;
|
|
75
76
|
|
|
76
77
|
class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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;
|
|
94
100
|
|
|
95
101
|
constructor(config: MultiActorEnvironmentConfig) {
|
|
96
102
|
this._actorEnvironments = new Map();
|
|
@@ -106,6 +112,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
106
112
|
this._relayFieldLogger = config.relayFieldLogger ?? defaultRelayFieldLogger;
|
|
107
113
|
this._shouldProcessClientComponents = config.shouldProcessClientComponents;
|
|
108
114
|
this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull ?? false;
|
|
115
|
+
this._deferDeduplicatedFields = config.deferDeduplicatedFields ?? false;
|
|
109
116
|
this._isServer = config.isServer ?? false;
|
|
110
117
|
this._missingFieldHandlers = config.missingFieldHandlers ?? [];
|
|
111
118
|
this._createStoreForActor = config.createStoreForActor;
|
|
@@ -175,7 +182,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
175
182
|
_checkSelectorAndHandleMissingFields(
|
|
176
183
|
actorEnvironment: IActorEnvironment,
|
|
177
184
|
operation: OperationDescriptor,
|
|
178
|
-
handlers:
|
|
185
|
+
handlers: ReadonlyArray<MissingFieldHandler>,
|
|
179
186
|
): OperationAvailability {
|
|
180
187
|
const targets: Map<ActorIdentifier, MutableRecordSource> = new Map([
|
|
181
188
|
[actorEnvironment.actorIdentifier, RelayRecordSource.create()],
|
|
@@ -267,7 +274,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
267
274
|
});
|
|
268
275
|
}
|
|
269
276
|
|
|
270
|
-
applyMutation<TMutation
|
|
277
|
+
applyMutation<TMutation extends MutationParameters>(
|
|
271
278
|
actorEnvironment: IActorEnvironment,
|
|
272
279
|
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
273
280
|
): Disposable {
|
|
@@ -341,7 +348,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
341
348
|
});
|
|
342
349
|
}
|
|
343
350
|
|
|
344
|
-
executeSubscription<TMutation
|
|
351
|
+
executeSubscription<TMutation extends MutationParameters>(
|
|
345
352
|
actorEnvironment: IActorEnvironment,
|
|
346
353
|
{
|
|
347
354
|
operation,
|
|
@@ -368,7 +375,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
368
375
|
});
|
|
369
376
|
}
|
|
370
377
|
|
|
371
|
-
executeMutation<TMutation
|
|
378
|
+
executeMutation<TMutation extends MutationParameters>(
|
|
372
379
|
actorEnvironment: IActorEnvironment,
|
|
373
380
|
{
|
|
374
381
|
operation,
|
|
@@ -432,7 +439,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
432
439
|
return this._isServer;
|
|
433
440
|
}
|
|
434
441
|
|
|
435
|
-
_execute<TMutation
|
|
442
|
+
_execute<TMutation extends MutationParameters>(
|
|
436
443
|
actorEnvironment: IActorEnvironment,
|
|
437
444
|
{
|
|
438
445
|
createSource,
|
|
@@ -471,6 +478,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
471
478
|
return this.forActor(actorIdentifier).getStore();
|
|
472
479
|
},
|
|
473
480
|
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
481
|
+
deferDeduplicatedFields: this._deferDeduplicatedFields,
|
|
474
482
|
updater,
|
|
475
483
|
log: this._logFn,
|
|
476
484
|
normalizeResponse: this._normalizeResponse,
|
|
@@ -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
|
/**
|
|
@@ -140,7 +140,7 @@ export interface IMultiActorEnvironment {
|
|
|
140
140
|
* Apply an optimistic mutation response and/or updater. The mutation can be
|
|
141
141
|
* reverted by calling `dispose()` on the returned value.
|
|
142
142
|
*/
|
|
143
|
-
applyMutation<TMutation
|
|
143
|
+
applyMutation<TMutation extends MutationParameters>(
|
|
144
144
|
actorEnvironment: IActorEnvironment,
|
|
145
145
|
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
146
146
|
): Disposable;
|
|
@@ -203,7 +203,7 @@ export interface IMultiActorEnvironment {
|
|
|
203
203
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
204
204
|
* the result is subscribed to: environment.executeSubscription({...}).subscribe({...}).
|
|
205
205
|
*/
|
|
206
|
-
executeSubscription<TMutation
|
|
206
|
+
executeSubscription<TMutation extends MutationParameters>(
|
|
207
207
|
actorEnvironment: IActorEnvironment,
|
|
208
208
|
config: {
|
|
209
209
|
operation: OperationDescriptor,
|
|
@@ -221,7 +221,7 @@ export interface IMultiActorEnvironment {
|
|
|
221
221
|
* the result is subscribed to:
|
|
222
222
|
* environment.executeMutation({...}).subscribe({...}).
|
|
223
223
|
*/
|
|
224
|
-
executeMutation<TMutation
|
|
224
|
+
executeMutation<TMutation extends MutationParameters>(
|
|
225
225
|
actorEnvironment: IActorEnvironment,
|
|
226
226
|
config: ExecuteMutationConfig<TMutation>,
|
|
227
227
|
): RelayObservable<GraphQLResponse>;
|
|
@@ -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
|
+
};
|
|
@@ -27,13 +27,13 @@ const MutationTypes = Object.freeze({
|
|
|
27
27
|
RANGE_DELETE: 'RANGE_DELETE',
|
|
28
28
|
NODE_DELETE: 'NODE_DELETE',
|
|
29
29
|
});
|
|
30
|
-
export type MutationType =
|
|
30
|
+
export type MutationType = Values<typeof MutationTypes>;
|
|
31
31
|
|
|
32
32
|
const RangeOperations = Object.freeze({
|
|
33
33
|
APPEND: 'append',
|
|
34
34
|
PREPEND: 'prepend',
|
|
35
35
|
});
|
|
36
|
-
export type RangeOperation =
|
|
36
|
+
export type RangeOperation = Values<typeof RangeOperations>;
|
|
37
37
|
|
|
38
38
|
type RangeBehaviorsFunction = (connectionArgs: {
|
|
39
39
|
[name: string]: $FlowFixMe,
|
|
@@ -82,7 +82,7 @@ export type DeclarativeMutationConfig =
|
|
|
82
82
|
| RangeDeleteConfig
|
|
83
83
|
| NodeDeleteConfig;
|
|
84
84
|
|
|
85
|
-
function convert<TMutation
|
|
85
|
+
function convert<TMutation extends MutationParameters>(
|
|
86
86
|
configs: Array<DeclarativeMutationConfig>,
|
|
87
87
|
request: ConcreteRequest,
|
|
88
88
|
optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
@@ -145,13 +145,13 @@ function convert<TMutation: MutationParameters>(
|
|
|
145
145
|
function nodeDelete(
|
|
146
146
|
config: NodeDeleteConfig,
|
|
147
147
|
request: ConcreteRequest,
|
|
148
|
-
): ?SelectorStoreUpdater<
|
|
148
|
+
): ?SelectorStoreUpdater<unknown> {
|
|
149
149
|
const {deletedIDFieldName} = config;
|
|
150
150
|
const rootField = getRootField(request);
|
|
151
151
|
if (!rootField) {
|
|
152
152
|
return null;
|
|
153
153
|
}
|
|
154
|
-
return (store: RecordSourceSelectorProxy, data: ?
|
|
154
|
+
return (store: RecordSourceSelectorProxy, data: ?unknown) => {
|
|
155
155
|
const payload = store.getRootField(rootField);
|
|
156
156
|
if (!payload) {
|
|
157
157
|
return;
|
|
@@ -169,7 +169,7 @@ function nodeDelete(
|
|
|
169
169
|
function rangeAdd(
|
|
170
170
|
config: RangeAddConfig,
|
|
171
171
|
request: ConcreteRequest,
|
|
172
|
-
): ?SelectorStoreUpdater<
|
|
172
|
+
): ?SelectorStoreUpdater<unknown> {
|
|
173
173
|
const {parentID, connectionInfo, edgeName} = config;
|
|
174
174
|
if (!parentID) {
|
|
175
175
|
warning(
|
|
@@ -183,7 +183,7 @@ function rangeAdd(
|
|
|
183
183
|
if (!connectionInfo || !rootField) {
|
|
184
184
|
return null;
|
|
185
185
|
}
|
|
186
|
-
return (store: RecordSourceSelectorProxy, data: ?
|
|
186
|
+
return (store: RecordSourceSelectorProxy, data: ?unknown) => {
|
|
187
187
|
const parent = store.get(parentID);
|
|
188
188
|
if (!parent) {
|
|
189
189
|
return;
|
|
@@ -237,7 +237,7 @@ function rangeAdd(
|
|
|
237
237
|
function rangeDelete(
|
|
238
238
|
config: RangeDeleteConfig,
|
|
239
239
|
request: ConcreteRequest,
|
|
240
|
-
): ?SelectorStoreUpdater<
|
|
240
|
+
): ?SelectorStoreUpdater<unknown> {
|
|
241
241
|
const {parentID, connectionKeys, pathToConnection, deletedIDFieldName} =
|
|
242
242
|
config;
|
|
243
243
|
if (!parentID) {
|
|
@@ -252,7 +252,7 @@ function rangeDelete(
|
|
|
252
252
|
if (!rootField) {
|
|
253
253
|
return null;
|
|
254
254
|
}
|
|
255
|
-
return (store: RecordSourceSelectorProxy, data: ?
|
|
255
|
+
return (store: RecordSourceSelectorProxy, data: ?unknown) => {
|
|
256
256
|
if (!data) {
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
@@ -61,16 +61,16 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
61
61
|
return type;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
getValue(name: string, args?: ?Arguments):
|
|
64
|
+
getValue(name: string, args?: ?Arguments): unknown {
|
|
65
65
|
const storageKey = getStableStorageKey(name, args);
|
|
66
66
|
return this._mutator.getValue(this._dataID, storageKey);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
setValue(
|
|
70
|
-
value:
|
|
70
|
+
value: unknown,
|
|
71
71
|
name: string,
|
|
72
72
|
args?: ?Arguments,
|
|
73
|
-
errors?:
|
|
73
|
+
errors?: ?ReadonlyArray<TRelayFieldError>,
|
|
74
74
|
): RecordProxy {
|
|
75
75
|
invariant(
|
|
76
76
|
isValidLeafValue(value),
|
|
@@ -82,10 +82,7 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
82
82
|
return this.setValue__UNSAFE(value, name, args, errors);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
getErrors(
|
|
86
|
-
name: string,
|
|
87
|
-
args?: ?Arguments,
|
|
88
|
-
): ?$ReadOnlyArray<TRelayFieldError> {
|
|
85
|
+
getErrors(name: string, args?: ?Arguments): ?ReadonlyArray<TRelayFieldError> {
|
|
89
86
|
const storageKey = getStableStorageKey(name, args);
|
|
90
87
|
return this._mutator.getErrors(this._dataID, storageKey);
|
|
91
88
|
}
|
|
@@ -94,10 +91,10 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
94
91
|
// We already validated that the value has the correct type
|
|
95
92
|
// so it should be safe to store complex structures as scalar values (custom scalars)
|
|
96
93
|
setValue__UNSAFE(
|
|
97
|
-
value:
|
|
94
|
+
value: unknown,
|
|
98
95
|
name: string,
|
|
99
96
|
args?: ?Arguments,
|
|
100
|
-
errors?:
|
|
97
|
+
errors?: ?ReadonlyArray<TRelayFieldError>,
|
|
101
98
|
): RecordProxy {
|
|
102
99
|
const storageKey = getStableStorageKey(name, args);
|
|
103
100
|
this._mutator.setValue(this._dataID, storageKey, value);
|
|
@@ -166,7 +163,7 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
166
163
|
}
|
|
167
164
|
|
|
168
165
|
setLinkedRecords(
|
|
169
|
-
records:
|
|
166
|
+
records: ReadonlyArray<?RecordProxy>,
|
|
170
167
|
name: string,
|
|
171
168
|
args?: ?Arguments,
|
|
172
169
|
): RecordProxy {
|
|
@@ -186,7 +183,7 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
186
183
|
}
|
|
187
184
|
}
|
|
188
185
|
|
|
189
|
-
function isValidLeafValue(value:
|
|
186
|
+
function isValidLeafValue(value: unknown): boolean {
|
|
190
187
|
return (
|
|
191
188
|
value == null ||
|
|
192
189
|
typeof value !== 'object' ||
|
|
@@ -161,7 +161,7 @@ class RelayRecordSourceMutator {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
getValue(dataID: DataID, storageKey: string):
|
|
164
|
+
getValue(dataID: DataID, storageKey: string): unknown {
|
|
165
165
|
for (let ii = 0; ii < this.__sources.length; ii++) {
|
|
166
166
|
const record = this.__sources[ii].get(dataID);
|
|
167
167
|
if (record) {
|
|
@@ -175,7 +175,7 @@ class RelayRecordSourceMutator {
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
setValue(dataID: DataID, storageKey: string, value:
|
|
178
|
+
setValue(dataID: DataID, storageKey: string, value: unknown): void {
|
|
179
179
|
const sinkRecord = this._getSinkRecord(dataID);
|
|
180
180
|
RelayModernRecord.setValue(sinkRecord, storageKey, value);
|
|
181
181
|
}
|
|
@@ -183,7 +183,7 @@ class RelayRecordSourceMutator {
|
|
|
183
183
|
getErrors(
|
|
184
184
|
dataID: DataID,
|
|
185
185
|
storageKey: string,
|
|
186
|
-
):
|
|
186
|
+
): ?ReadonlyArray<TRelayFieldError> {
|
|
187
187
|
for (let ii = 0; ii < this.__sources.length; ii++) {
|
|
188
188
|
const record = this.__sources[ii].get(dataID);
|
|
189
189
|
if (record) {
|
|
@@ -200,7 +200,7 @@ class RelayRecordSourceMutator {
|
|
|
200
200
|
setErrors(
|
|
201
201
|
dataID: DataID,
|
|
202
202
|
storageKey: string,
|
|
203
|
-
errors?:
|
|
203
|
+
errors?: ReadonlyArray<TRelayFieldError>,
|
|
204
204
|
): void {
|
|
205
205
|
const sinkRecord = this._getSinkRecord(dataID);
|
|
206
206
|
RelayModernRecord.setErrors(sinkRecord, storageKey, errors);
|