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
|
@@ -0,0 +1,92 @@
|
|
|
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 { DataID } from '../util/RelayRuntimeTypes';
|
|
9
|
+
import { Record } from './RelayStoreTypes';
|
|
10
|
+
|
|
11
|
+
export class RelayModernRecord {
|
|
12
|
+
/**
|
|
13
|
+
* Clone a record.
|
|
14
|
+
*/
|
|
15
|
+
clone(record: Record): Record;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Copies all fields from `source` to `sink`, excluding `__id` and `__typename`.
|
|
19
|
+
*
|
|
20
|
+
* NOTE: This function does not treat `id` specially. To preserve the id,
|
|
21
|
+
* manually reset it after calling this function. Also note that values are
|
|
22
|
+
* copied by reference and not value; callers should ensure that values are
|
|
23
|
+
* copied on write.
|
|
24
|
+
*/
|
|
25
|
+
copyFields(source: Record, sink: Record): void;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Create a new record.
|
|
29
|
+
*/
|
|
30
|
+
create(dataID: DataID, typeName: string): Record;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get the record's `id` if available or the client-generated identifier.
|
|
34
|
+
*/
|
|
35
|
+
getDataID(record: Record): DataID;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the concrete type of the record.
|
|
39
|
+
*/
|
|
40
|
+
getType(record: Record): string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get a scalar (non-link) field value.
|
|
44
|
+
*/
|
|
45
|
+
getValue(record: Record, storageKey: string): unknown;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the value of a field as a reference to another record. Throws if the
|
|
49
|
+
* field has a different type.
|
|
50
|
+
*/
|
|
51
|
+
getLinkedRecordID(record: Record, storageKey: string): DataID | null;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get the value of a field as a list of references to other records. Throws if
|
|
55
|
+
* the field has a different type.
|
|
56
|
+
*/
|
|
57
|
+
getLinkedRecordIDs(record: Record, storageKey: string): DataID[] | null;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Compares the fields of a previous and new record, returning either the
|
|
61
|
+
* previous record if all fields are equal or a new record (with merged fields)
|
|
62
|
+
* if any fields have changed.
|
|
63
|
+
*/
|
|
64
|
+
update(prevRecord: Record, nextRecord: Record): Record;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Returns a new record with the contents of the given records. Fields in the
|
|
68
|
+
* second record will overwrite identical fields in the first record.
|
|
69
|
+
*/
|
|
70
|
+
merge(record1: Record, record2: Record): Record;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Prevent modifications to the record. Attempts to call `set*` functions on a
|
|
74
|
+
* frozen record will fatal at runtime.
|
|
75
|
+
*/
|
|
76
|
+
freeze(record: Record): void;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Set the value of a storageKey to a scalar.
|
|
80
|
+
*/
|
|
81
|
+
setValue(record: Record, storageKey: string, value: any): void;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Set the value of a field to a reference to another record.
|
|
85
|
+
*/
|
|
86
|
+
setLinkedRecordID(record: Record, storageKey: string, linkedID: DataID): void;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Set the value of a field to a list of references other records.
|
|
90
|
+
*/
|
|
91
|
+
setLinkedRecordIDs(record: Record, storageKey: string, linkedIDs: DataID[] | null): void;
|
|
92
|
+
}
|
|
@@ -37,7 +37,7 @@ const warning = require('warning');
|
|
|
37
37
|
|
|
38
38
|
export type StorageKey = Exclude<string, typeof ERRORS_KEY>;
|
|
39
39
|
|
|
40
|
-
type RelayFieldErrors = {[StorageKey]:
|
|
40
|
+
type RelayFieldErrors = {[StorageKey]: ReadonlyArray<TRelayFieldError>};
|
|
41
41
|
|
|
42
42
|
export type RecordJSON = {
|
|
43
43
|
/**
|
|
@@ -45,7 +45,7 @@ export type RecordJSON = {
|
|
|
45
45
|
* not support types with multiple indexers.
|
|
46
46
|
*/
|
|
47
47
|
__errors?: RelayFieldErrors,
|
|
48
|
-
[StorageKey]:
|
|
48
|
+
[StorageKey]: unknown,
|
|
49
49
|
...
|
|
50
50
|
};
|
|
51
51
|
|
|
@@ -147,7 +147,7 @@ function create(dataID: DataID, typeName: string): Record {
|
|
|
147
147
|
*
|
|
148
148
|
* Convert the JSON representation of a record into a record.
|
|
149
149
|
*/
|
|
150
|
-
function fromObject<TMaybe
|
|
150
|
+
function fromObject<TMaybe extends ?empty = empty>(
|
|
151
151
|
json: RecordJSON | TMaybe,
|
|
152
152
|
): Record | TMaybe {
|
|
153
153
|
return json;
|
|
@@ -159,7 +159,7 @@ function fromObject<TMaybe: ?empty = empty>(
|
|
|
159
159
|
* Get the record's `id` if available or the client-generated identifier.
|
|
160
160
|
*/
|
|
161
161
|
function getDataID(record: Record): DataID {
|
|
162
|
-
return
|
|
162
|
+
return record[ID_KEY] as any;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
/**
|
|
@@ -180,7 +180,7 @@ function getFields(record: Record): Array<StorageKey> {
|
|
|
180
180
|
* Get the concrete type of the record.
|
|
181
181
|
*/
|
|
182
182
|
function getType(record: Record): string {
|
|
183
|
-
return
|
|
183
|
+
return record[TYPENAME_KEY] as any;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
/**
|
|
@@ -191,7 +191,7 @@ function getType(record: Record): string {
|
|
|
191
191
|
function getErrors(
|
|
192
192
|
record: Record,
|
|
193
193
|
storageKey: StorageKey,
|
|
194
|
-
):
|
|
194
|
+
): ReadonlyArray<TRelayFieldError> | void {
|
|
195
195
|
return record[ERRORS_KEY]?.[storageKey];
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -200,7 +200,7 @@ function getErrors(
|
|
|
200
200
|
*
|
|
201
201
|
* Get a scalar (non-link) field value.
|
|
202
202
|
*/
|
|
203
|
-
function getValue(record: Record, storageKey: StorageKey):
|
|
203
|
+
function getValue(record: Record, storageKey: StorageKey): unknown {
|
|
204
204
|
const value = record[storageKey];
|
|
205
205
|
if (value && typeof value === 'object') {
|
|
206
206
|
invariant(
|
|
@@ -252,7 +252,7 @@ function getLinkedRecordID(record: Record, storageKey: StorageKey): ?DataID {
|
|
|
252
252
|
'getLinkedRecords() instead of getLinkedRecord()?'
|
|
253
253
|
: '',
|
|
254
254
|
);
|
|
255
|
-
// $FlowFixMe[incompatible-
|
|
255
|
+
// $FlowFixMe[incompatible-type]
|
|
256
256
|
return link[REF_KEY];
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -297,7 +297,7 @@ function getLinkedRecordIDs(
|
|
|
297
297
|
: '',
|
|
298
298
|
);
|
|
299
299
|
// assume items of the array are ids
|
|
300
|
-
return
|
|
300
|
+
return links[REFS_KEY] as any;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
/**
|
|
@@ -488,7 +488,7 @@ function freeze(record: Record): void {
|
|
|
488
488
|
function setErrors(
|
|
489
489
|
record: Record,
|
|
490
490
|
storageKey: StorageKey,
|
|
491
|
-
errors?:
|
|
491
|
+
errors?: ReadonlyArray<TRelayFieldError>,
|
|
492
492
|
): void {
|
|
493
493
|
if (__DEV__) {
|
|
494
494
|
warning(
|
|
@@ -523,7 +523,11 @@ function setErrors(
|
|
|
523
523
|
*
|
|
524
524
|
* Set the value of a storageKey to a scalar.
|
|
525
525
|
*/
|
|
526
|
-
function setValue(
|
|
526
|
+
function setValue(
|
|
527
|
+
record: Record,
|
|
528
|
+
storageKey: StorageKey,
|
|
529
|
+
value: unknown,
|
|
530
|
+
): void {
|
|
527
531
|
if (__DEV__) {
|
|
528
532
|
const prevID = getDataID(record);
|
|
529
533
|
if (storageKey === ID_KEY) {
|
|
@@ -629,7 +633,7 @@ function getActorLinkedRecordID(
|
|
|
629
633
|
JSON.stringify(link),
|
|
630
634
|
);
|
|
631
635
|
|
|
632
|
-
return [
|
|
636
|
+
return [link[ACTOR_IDENTIFIER_KEY] as any, link[REF_KEY] as any];
|
|
633
637
|
}
|
|
634
638
|
|
|
635
639
|
function getResolverLinkedRecordID(record: Record, typeName: string): ?DataID {
|
|
@@ -682,12 +686,31 @@ function getResolverLinkedRecordIDs(
|
|
|
682
686
|
});
|
|
683
687
|
}
|
|
684
688
|
|
|
689
|
+
/**
|
|
690
|
+
* @public
|
|
691
|
+
*
|
|
692
|
+
* Returns true if the value of a field differs between two records.
|
|
693
|
+
* Unlike getValue(), this works for all field types (scalar, linked, plural linked).
|
|
694
|
+
*/
|
|
695
|
+
function hasFieldChanged(
|
|
696
|
+
prevRecord: Record,
|
|
697
|
+
nextRecord: Record,
|
|
698
|
+
storageKey: StorageKey,
|
|
699
|
+
): boolean {
|
|
700
|
+
if (!areEqual(prevRecord[storageKey], nextRecord[storageKey])) {
|
|
701
|
+
return true;
|
|
702
|
+
}
|
|
703
|
+
const prevErrors = prevRecord[ERRORS_KEY]?.[storageKey];
|
|
704
|
+
const nextErrors = nextRecord[ERRORS_KEY]?.[storageKey];
|
|
705
|
+
return !areEqual(prevErrors, nextErrors);
|
|
706
|
+
}
|
|
707
|
+
|
|
685
708
|
/**
|
|
686
709
|
* @public
|
|
687
710
|
*
|
|
688
711
|
* Convert a record to JSON.
|
|
689
712
|
*/
|
|
690
|
-
function toJSON<TMaybe
|
|
713
|
+
function toJSON<TMaybe extends ?empty = empty>(
|
|
691
714
|
record: Record | TMaybe,
|
|
692
715
|
): RecordJSON | TMaybe {
|
|
693
716
|
return record;
|
|
@@ -699,26 +722,27 @@ module.exports = {
|
|
|
699
722
|
create,
|
|
700
723
|
freeze,
|
|
701
724
|
fromObject,
|
|
725
|
+
getActorLinkedRecordID,
|
|
702
726
|
getDataID,
|
|
703
727
|
getErrors,
|
|
704
728
|
getFields,
|
|
705
729
|
getInvalidationEpoch,
|
|
706
730
|
getLinkedRecordID,
|
|
707
731
|
getLinkedRecordIDs,
|
|
732
|
+
getResolverLinkedRecordID,
|
|
733
|
+
getResolverLinkedRecordIDs,
|
|
708
734
|
getType,
|
|
709
735
|
getValue,
|
|
710
|
-
|
|
736
|
+
hasFieldChanged,
|
|
711
737
|
hasLinkedRecordID,
|
|
712
738
|
hasLinkedRecordIDs,
|
|
739
|
+
hasValue,
|
|
713
740
|
merge,
|
|
741
|
+
setActorLinkedRecordID,
|
|
714
742
|
setErrors,
|
|
715
|
-
setValue,
|
|
716
743
|
setLinkedRecordID,
|
|
717
744
|
setLinkedRecordIDs,
|
|
718
|
-
|
|
719
|
-
getActorLinkedRecordID,
|
|
720
|
-
setActorLinkedRecordID,
|
|
721
|
-
getResolverLinkedRecordID,
|
|
722
|
-
getResolverLinkedRecordIDs,
|
|
745
|
+
setValue,
|
|
723
746
|
toJSON,
|
|
747
|
+
update,
|
|
724
748
|
};
|
|
@@ -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 { NormalizationSelectableNode } from '../util/NormalizationNode';
|
|
9
|
+
import { ReaderFragment } from '../util/ReaderNode';
|
|
10
|
+
import {DataID, Variables} from '../util/RelayRuntimeTypes';
|
|
11
|
+
import {
|
|
12
|
+
NormalizationSelector,
|
|
13
|
+
PluralReaderSelector,
|
|
14
|
+
ReaderSelector,
|
|
15
|
+
RequestDescriptor,
|
|
16
|
+
SingularReaderSelector,
|
|
17
|
+
} from './RelayStoreTypes';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Given the result `item` from a parent that fetched `fragment`, creates a
|
|
21
|
+
* selector that can be used to read the results of that fragment for that item.
|
|
22
|
+
*
|
|
23
|
+
* Example:
|
|
24
|
+
*
|
|
25
|
+
* Given two fragments as follows:
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
* fragment Parent on User {
|
|
29
|
+
* id
|
|
30
|
+
* ...Child
|
|
31
|
+
* }
|
|
32
|
+
* fragment Child on User {
|
|
33
|
+
* name
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* And given some object `parent` that is the results of `Parent` for id "4",
|
|
38
|
+
* the results of `Child` can be accessed by first getting a selector and then
|
|
39
|
+
* using that selector to `lookup()` the results against the environment:
|
|
40
|
+
*
|
|
41
|
+
* ```
|
|
42
|
+
* const childSelector = getSingularSelector(queryVariables, Child, parent);
|
|
43
|
+
* const childData = environment.lookup(childSelector).data;
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function getSingularSelector(fragment: ReaderFragment, item: unknown): SingularReaderSelector;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Given the result `items` from a parent that fetched `fragment`, creates a
|
|
50
|
+
* selector that can be used to read the results of that fragment on those
|
|
51
|
+
* items. This is similar to `getSingularSelector` but for "plural" fragments that
|
|
52
|
+
* expect an array of results and therefore return an array of selectors.
|
|
53
|
+
*/
|
|
54
|
+
export function getPluralSelector(fragment: ReaderFragment, items: unknown[]): PluralReaderSelector;
|
|
55
|
+
|
|
56
|
+
export function getSelector(fragment: ReaderFragment, item: unknown | unknown[]): ReaderSelector;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Given a mapping of keys -> results and a mapping of keys -> fragments,
|
|
60
|
+
* extracts the selectors for those fragments from the results.
|
|
61
|
+
*
|
|
62
|
+
* The canonical use-case for this function is ReactRelayFragmentContainer, which
|
|
63
|
+
* uses this function to convert (props, fragments) into selectors so that it
|
|
64
|
+
* can read the results to pass to the inner component.
|
|
65
|
+
*/
|
|
66
|
+
export function getSelectorsFromObject(
|
|
67
|
+
fragments: { [key: string]: ReaderFragment },
|
|
68
|
+
object: { [key: string]: any },
|
|
69
|
+
): { [key: string]: ReaderSelector };
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Given a mapping of keys -> results and a mapping of keys -> fragments,
|
|
73
|
+
* extracts a mapping of keys -> id(s) of the results.
|
|
74
|
+
*
|
|
75
|
+
* Similar to `getSelectorsFromObject()`, this function can be useful in
|
|
76
|
+
* determining the "identity" of the props passed to a component.
|
|
77
|
+
*/
|
|
78
|
+
export function getDataIDsFromObject(
|
|
79
|
+
fragments: { [key: string]: ReaderFragment },
|
|
80
|
+
object: { [key: string]: any },
|
|
81
|
+
): { [key: string]: DataID | DataID[] };
|
|
82
|
+
|
|
83
|
+
export function getDataIDsFromFragment(fragment: ReaderFragment, item: unknown | unknown[]): DataID | DataID[];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Given a mapping of keys -> results and a mapping of keys -> fragments,
|
|
87
|
+
* extracts the merged variables that would be in scope for those
|
|
88
|
+
* fragments/results.
|
|
89
|
+
*
|
|
90
|
+
* This can be useful in determing what varaibles were used to fetch the data
|
|
91
|
+
* for a Relay container, for example.
|
|
92
|
+
*/
|
|
93
|
+
export function getVariablesFromObject(
|
|
94
|
+
fragments: { [key: string]: ReaderFragment },
|
|
95
|
+
object: { [key: string]: any },
|
|
96
|
+
): Variables;
|
|
97
|
+
|
|
98
|
+
export function getVariablesFromFragment(fragment: ReaderFragment, item: unknown | unknown[]): Variables;
|
|
99
|
+
|
|
100
|
+
export function getVariablesFromSingularFragment(fragment: ReaderFragment, item: unknown): Variables;
|
|
101
|
+
|
|
102
|
+
export function getVariablesFromPluralFragment(fragment: ReaderFragment, items: unknown[]): Variables;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Determine if two selectors are equal (represent the same selection). Note
|
|
106
|
+
* that this function returns `false` when the two queries/fragments are
|
|
107
|
+
* different objects, even if they select the same fields.
|
|
108
|
+
*/
|
|
109
|
+
export function areEqualSelectors(thisSelector: SingularReaderSelector, thatSelector: SingularReaderSelector): boolean;
|
|
110
|
+
|
|
111
|
+
export function createReaderSelector(
|
|
112
|
+
fragment: ReaderFragment,
|
|
113
|
+
dataID: DataID,
|
|
114
|
+
variables: Variables,
|
|
115
|
+
request: RequestDescriptor,
|
|
116
|
+
isWithinUnmatchedTypeRefinement?: boolean, // default: `false`
|
|
117
|
+
): SingularReaderSelector;
|
|
118
|
+
|
|
119
|
+
export function createNormalizationSelector(
|
|
120
|
+
node: NormalizationSelectableNode,
|
|
121
|
+
dataID: DataID,
|
|
122
|
+
variables: Variables,
|
|
123
|
+
): NormalizationSelector;
|
|
@@ -66,7 +66,7 @@ const warning = require('warning');
|
|
|
66
66
|
*/
|
|
67
67
|
function getSingularSelector(
|
|
68
68
|
fragment: ReaderFragment,
|
|
69
|
-
item:
|
|
69
|
+
item: unknown,
|
|
70
70
|
): ?SingularReaderSelector {
|
|
71
71
|
invariant(
|
|
72
72
|
typeof item === 'object' && item !== null && !Array.isArray(item),
|
|
@@ -90,9 +90,9 @@ function getSingularSelector(
|
|
|
90
90
|
(mixedClientEdgeTraversalPath == null ||
|
|
91
91
|
Array.isArray(mixedClientEdgeTraversalPath))
|
|
92
92
|
) {
|
|
93
|
-
const owner: RequestDescriptor =
|
|
93
|
+
const owner: RequestDescriptor = mixedOwner as $FlowFixMe;
|
|
94
94
|
const clientEdgeTraversalPath: ?ClientEdgeTraversalPath =
|
|
95
|
-
|
|
95
|
+
mixedClientEdgeTraversalPath as $FlowFixMe;
|
|
96
96
|
|
|
97
97
|
const argumentVariables = fragments[fragment.name];
|
|
98
98
|
const fragmentVariables = getFragmentVariables(
|
|
@@ -146,7 +146,7 @@ function getSingularSelector(
|
|
|
146
146
|
*/
|
|
147
147
|
function getPluralSelector(
|
|
148
148
|
fragment: ReaderFragment,
|
|
149
|
-
items:
|
|
149
|
+
items: ReadonlyArray<unknown>,
|
|
150
150
|
): ?PluralReaderSelector {
|
|
151
151
|
let selectors: null | Array<SingularReaderSelector> = null;
|
|
152
152
|
items.forEach((item, ii) => {
|
|
@@ -168,7 +168,7 @@ function getPluralSelector(
|
|
|
168
168
|
|
|
169
169
|
function getSelector(
|
|
170
170
|
fragment: ReaderFragment,
|
|
171
|
-
item:
|
|
171
|
+
item: unknown | Array<unknown>,
|
|
172
172
|
): ?ReaderSelector {
|
|
173
173
|
if (item == null) {
|
|
174
174
|
return item;
|
|
@@ -207,7 +207,7 @@ function getSelector(
|
|
|
207
207
|
*/
|
|
208
208
|
function getSelectorsFromObject(
|
|
209
209
|
fragments: {[key: string]: ReaderFragment, ...},
|
|
210
|
-
object: {[key: string]:
|
|
210
|
+
object: {[key: string]: unknown, ...},
|
|
211
211
|
): {[key: string]: ?ReaderSelector, ...} {
|
|
212
212
|
const selectors: {[string]: ?ReaderSelector} = {};
|
|
213
213
|
for (const key in fragments) {
|
|
@@ -231,7 +231,7 @@ function getSelectorsFromObject(
|
|
|
231
231
|
*/
|
|
232
232
|
function getDataIDsFromObject(
|
|
233
233
|
fragments: {[key: string]: ReaderFragment, ...},
|
|
234
|
-
object: {[key: string]:
|
|
234
|
+
object: {[key: string]: unknown, ...},
|
|
235
235
|
): {[key: string]: ?(DataID | Array<DataID>), ...} {
|
|
236
236
|
const ids: {[string]: ?(DataID | Array<DataID>)} = {};
|
|
237
237
|
for (const key in fragments) {
|
|
@@ -246,7 +246,7 @@ function getDataIDsFromObject(
|
|
|
246
246
|
|
|
247
247
|
function getDataIDsFromFragment(
|
|
248
248
|
fragment: ReaderFragment,
|
|
249
|
-
item:
|
|
249
|
+
item: unknown | Array<unknown>,
|
|
250
250
|
): ?DataID | ?Array<DataID> {
|
|
251
251
|
if (item == null) {
|
|
252
252
|
return item;
|
|
@@ -278,7 +278,7 @@ function getDataIDsFromFragment(
|
|
|
278
278
|
*/
|
|
279
279
|
function getDataIDs(
|
|
280
280
|
fragment: ReaderFragment,
|
|
281
|
-
items:
|
|
281
|
+
items: ReadonlyArray<unknown>,
|
|
282
282
|
): ?Array<DataID> {
|
|
283
283
|
let ids: null | Array<DataID> = null;
|
|
284
284
|
items.forEach(item => {
|
|
@@ -294,7 +294,7 @@ function getDataIDs(
|
|
|
294
294
|
/**
|
|
295
295
|
* @internal
|
|
296
296
|
*/
|
|
297
|
-
function getDataID(fragment: ReaderFragment, item:
|
|
297
|
+
function getDataID(fragment: ReaderFragment, item: unknown): ?DataID {
|
|
298
298
|
invariant(
|
|
299
299
|
typeof item === 'object' && item !== null && !Array.isArray(item),
|
|
300
300
|
'RelayModernSelector: Expected value for fragment `%s` to be an object, got ' +
|
|
@@ -332,7 +332,7 @@ function getDataID(fragment: ReaderFragment, item: mixed): ?DataID {
|
|
|
332
332
|
*/
|
|
333
333
|
function getVariablesFromObject(
|
|
334
334
|
fragments: {[key: string]: ReaderFragment, ...},
|
|
335
|
-
object: {[key: string]:
|
|
335
|
+
object: {[key: string]: unknown, ...},
|
|
336
336
|
): Variables {
|
|
337
337
|
const variables = {};
|
|
338
338
|
for (const key in fragments) {
|
|
@@ -349,7 +349,7 @@ function getVariablesFromObject(
|
|
|
349
349
|
|
|
350
350
|
function getVariablesFromFragment(
|
|
351
351
|
fragment: ReaderFragment,
|
|
352
|
-
item:
|
|
352
|
+
item: unknown | ReadonlyArray<unknown>,
|
|
353
353
|
): Variables {
|
|
354
354
|
if (item == null) {
|
|
355
355
|
return {};
|
|
@@ -380,7 +380,7 @@ function getVariablesFromFragment(
|
|
|
380
380
|
|
|
381
381
|
function getVariablesFromSingularFragment(
|
|
382
382
|
fragment: ReaderFragment,
|
|
383
|
-
item:
|
|
383
|
+
item: unknown,
|
|
384
384
|
): ?Variables {
|
|
385
385
|
const selector = getSingularSelector(fragment, item);
|
|
386
386
|
if (!selector) {
|
|
@@ -391,7 +391,7 @@ function getVariablesFromSingularFragment(
|
|
|
391
391
|
|
|
392
392
|
function getVariablesFromPluralFragment(
|
|
393
393
|
fragment: ReaderFragment,
|
|
394
|
-
items:
|
|
394
|
+
items: ReadonlyArray<unknown>,
|
|
395
395
|
): Variables {
|
|
396
396
|
const variables = {};
|
|
397
397
|
items.forEach((value, ii) => {
|
|
@@ -519,13 +519,13 @@ function createReaderSelector(
|
|
|
519
519
|
clientEdgeTraversalPath: ?ClientEdgeTraversalPath,
|
|
520
520
|
): SingularReaderSelector {
|
|
521
521
|
return {
|
|
522
|
-
|
|
522
|
+
clientEdgeTraversalPath: clientEdgeTraversalPath ?? null,
|
|
523
523
|
dataID,
|
|
524
524
|
isWithinUnmatchedTypeRefinement,
|
|
525
|
-
|
|
525
|
+
kind: 'SingularReaderSelector',
|
|
526
526
|
node: fragment,
|
|
527
|
-
variables,
|
|
528
527
|
owner: request,
|
|
528
|
+
variables,
|
|
529
529
|
};
|
|
530
530
|
}
|
|
531
531
|
|
|
@@ -539,16 +539,16 @@ function createNormalizationSelector(
|
|
|
539
539
|
|
|
540
540
|
module.exports = {
|
|
541
541
|
areEqualSelectors,
|
|
542
|
-
createReaderSelector,
|
|
543
542
|
createNormalizationSelector,
|
|
543
|
+
createReaderSelector,
|
|
544
544
|
getDataIDsFromFragment,
|
|
545
545
|
getDataIDsFromObject,
|
|
546
|
-
getSingularSelector,
|
|
547
546
|
getPluralSelector,
|
|
548
547
|
getSelector,
|
|
549
548
|
getSelectorsFromObject,
|
|
550
|
-
|
|
551
|
-
getVariablesFromPluralFragment,
|
|
549
|
+
getSingularSelector,
|
|
552
550
|
getVariablesFromFragment,
|
|
553
551
|
getVariablesFromObject,
|
|
552
|
+
getVariablesFromPluralFragment,
|
|
553
|
+
getVariablesFromSingularFragment,
|
|
554
554
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
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 {DataID, Disposable} from '../util/RelayRuntimeTypes';
|
|
9
|
+
import {
|
|
10
|
+
CheckOptions,
|
|
11
|
+
LogFunction,
|
|
12
|
+
MutableRecordSource,
|
|
13
|
+
OperationAvailability,
|
|
14
|
+
OperationDescriptor,
|
|
15
|
+
OperationLoader,
|
|
16
|
+
RecordSource,
|
|
17
|
+
RequestDescriptor,
|
|
18
|
+
ResolverContext,
|
|
19
|
+
Scheduler,
|
|
20
|
+
SingularReaderSelector,
|
|
21
|
+
Snapshot,
|
|
22
|
+
Store,
|
|
23
|
+
} from './RelayStoreTypes';
|
|
24
|
+
|
|
25
|
+
export interface InvalidationState {
|
|
26
|
+
dataIDs: readonly DataID[];
|
|
27
|
+
invalidations: Map<DataID, number | undefined | null>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default class RelayModernStore implements Store {
|
|
31
|
+
constructor(
|
|
32
|
+
source: MutableRecordSource,
|
|
33
|
+
options?: {
|
|
34
|
+
gcScheduler?: Scheduler | null | undefined;
|
|
35
|
+
log?: LogFunction | null | undefined;
|
|
36
|
+
operationLoader?: OperationLoader | null | undefined;
|
|
37
|
+
gcReleaseBufferSize?: number | null | undefined;
|
|
38
|
+
queryCacheExpirationTime?: number | null | undefined;
|
|
39
|
+
resolverContext?: ResolverContext;
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
getSource(): RecordSource;
|
|
43
|
+
check(operation: OperationDescriptor, options?: CheckOptions): OperationAvailability;
|
|
44
|
+
retain(operation: OperationDescriptor): Disposable;
|
|
45
|
+
lookup(selector: SingularReaderSelector): Snapshot;
|
|
46
|
+
notify(sourceOperation?: OperationDescriptor, invalidateStore?: boolean): readonly RequestDescriptor[];
|
|
47
|
+
publish(source: RecordSource, idsMarkedForInvalidation?: Set<DataID>): void;
|
|
48
|
+
subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable;
|
|
49
|
+
holdGC(): Disposable;
|
|
50
|
+
lookupInvalidationState(dataIDs: readonly DataID[]): InvalidationState;
|
|
51
|
+
checkInvalidationState(previousInvalidationState: InvalidationState): boolean;
|
|
52
|
+
subscribeToInvalidationState(invalidationState: InvalidationState, callback: () => void): Disposable;
|
|
53
|
+
toJSON(): unknown;
|
|
54
|
+
snapshot(): void;
|
|
55
|
+
restore(): void;
|
|
56
|
+
scheduleGC(): void;
|
|
57
|
+
}
|