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
|
@@ -46,6 +46,7 @@ const {
|
|
|
46
46
|
RELAY_RESOLVER_ERROR_KEY,
|
|
47
47
|
RELAY_RESOLVER_INVALIDATION_KEY,
|
|
48
48
|
RELAY_RESOLVER_OUTPUT_TYPE_RECORD_IDS,
|
|
49
|
+
RELAY_RESOLVER_RECORD_TYPENAME,
|
|
49
50
|
RELAY_RESOLVER_SNAPSHOT_KEY,
|
|
50
51
|
RELAY_RESOLVER_VALUE_KEY,
|
|
51
52
|
getReadTimeResolverStorageKey,
|
|
@@ -63,7 +64,6 @@ const RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY =
|
|
|
63
64
|
'__resolverLiveStateSubscription';
|
|
64
65
|
const RELAY_RESOLVER_LIVE_STATE_VALUE = '__resolverLiveStateValue';
|
|
65
66
|
const RELAY_RESOLVER_LIVE_STATE_DIRTY = '__resolverLiveStateDirty';
|
|
66
|
-
const RELAY_RESOLVER_RECORD_TYPENAME = '__RELAY_RESOLVER__';
|
|
67
67
|
const MODEL_PROPERTY_NAME = '__relay_model_instance';
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -181,7 +181,7 @@ class LiveResolverCache implements ResolverCache {
|
|
|
181
181
|
evaluationResult.error == null,
|
|
182
182
|
'Did not expect resolver to have both a value and an error.',
|
|
183
183
|
);
|
|
184
|
-
const liveState: LiveState<
|
|
184
|
+
const liveState: LiveState<unknown> =
|
|
185
185
|
// $FlowFixMe[incompatible-type] - casting mixed
|
|
186
186
|
evaluationResult.resolverResult;
|
|
187
187
|
updatedDataIDs = this._setLiveStateValue(
|
|
@@ -261,7 +261,7 @@ class LiveResolverCache implements ResolverCache {
|
|
|
261
261
|
linkedID = linkedID ?? generateClientID(recordID, storageKey);
|
|
262
262
|
linkedRecord = RelayModernRecord.clone(linkedRecord);
|
|
263
263
|
// $FlowFixMe[incompatible-type] - casting mixed
|
|
264
|
-
const liveState: LiveState<
|
|
264
|
+
const liveState: LiveState<unknown> = RelayModernRecord.getValue(
|
|
265
265
|
linkedRecord,
|
|
266
266
|
RELAY_RESOLVER_LIVE_STATE_VALUE,
|
|
267
267
|
);
|
|
@@ -327,7 +327,7 @@ class LiveResolverCache implements ResolverCache {
|
|
|
327
327
|
);
|
|
328
328
|
|
|
329
329
|
// $FlowFixMe[incompatible-type] - casting mixed
|
|
330
|
-
const liveState: LiveState<
|
|
330
|
+
const liveState: LiveState<unknown> = RelayModernRecord.getValue(
|
|
331
331
|
liveStateRecord,
|
|
332
332
|
RELAY_RESOLVER_LIVE_STATE_VALUE,
|
|
333
333
|
);
|
|
@@ -345,7 +345,7 @@ class LiveResolverCache implements ResolverCache {
|
|
|
345
345
|
_setLiveStateValue(
|
|
346
346
|
linkedRecord: Record,
|
|
347
347
|
linkedID: DataID,
|
|
348
|
-
liveState: LiveState<
|
|
348
|
+
liveState: LiveState<unknown>,
|
|
349
349
|
field: ReaderRelayLiveResolver,
|
|
350
350
|
variables: Variables,
|
|
351
351
|
): DataIDSet | null {
|
|
@@ -474,14 +474,39 @@ class LiveResolverCache implements ResolverCache {
|
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
+
// Returns true if source is published
|
|
478
|
+
batchLiveStateUpdatesWithoutNotify(callback: () => void): boolean {
|
|
479
|
+
invariant(
|
|
480
|
+
!this._handlingBatch,
|
|
481
|
+
'Unexpected nested call to batchLiveStateUpdates.',
|
|
482
|
+
);
|
|
483
|
+
this._handlingBatch = true;
|
|
484
|
+
try {
|
|
485
|
+
callback();
|
|
486
|
+
} finally {
|
|
487
|
+
const shouldPublish = this._liveResolverBatchRecordSource != null;
|
|
488
|
+
// We lazily create the record source. If one has not been created, there
|
|
489
|
+
// is nothing to publish.
|
|
490
|
+
if (shouldPublish) {
|
|
491
|
+
// $FlowFixMe[incompatible-type] Null checked
|
|
492
|
+
this._store.publish(this._liveResolverBatchRecordSource);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Reset batched state.
|
|
496
|
+
this._liveResolverBatchRecordSource = null;
|
|
497
|
+
this._handlingBatch = false;
|
|
498
|
+
return shouldPublish;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
477
502
|
_setLiveResolverValue(
|
|
478
503
|
resolverRecord: Record,
|
|
479
|
-
liveValue: LiveState<
|
|
504
|
+
liveValue: LiveState<unknown>,
|
|
480
505
|
field: ReaderRelayResolver | ReaderRelayLiveResolver,
|
|
481
506
|
variables: Variables,
|
|
482
507
|
): DataIDSet | null {
|
|
483
|
-
let value: null |
|
|
484
|
-
let resolverError: null |
|
|
508
|
+
let value: null | unknown = null;
|
|
509
|
+
let resolverError: null | unknown = null;
|
|
485
510
|
try {
|
|
486
511
|
value = liveValue.read();
|
|
487
512
|
} catch (e) {
|
|
@@ -498,7 +523,7 @@ class LiveResolverCache implements ResolverCache {
|
|
|
498
523
|
|
|
499
524
|
_setResolverValue(
|
|
500
525
|
resolverRecord: Record,
|
|
501
|
-
value:
|
|
526
|
+
value: unknown,
|
|
502
527
|
field: ReaderRelayResolver | ReaderRelayLiveResolver,
|
|
503
528
|
variables: Variables,
|
|
504
529
|
): DataIDSet | null {
|
|
@@ -623,13 +648,23 @@ class LiveResolverCache implements ResolverCache {
|
|
|
623
648
|
);
|
|
624
649
|
} else {
|
|
625
650
|
shallowFreeze(value);
|
|
626
|
-
|
|
627
|
-
// value
|
|
651
|
+
|
|
652
|
+
// For "classic" resolvers (or if the value is nullish/suspense), we are
|
|
653
|
+
// set their value...
|
|
628
654
|
RelayModernRecord.setValue(
|
|
629
655
|
resolverRecord,
|
|
630
656
|
RELAY_RESOLVER_VALUE_KEY,
|
|
631
657
|
value,
|
|
632
658
|
);
|
|
659
|
+
|
|
660
|
+
// ...and clear the output type record IDs, if any since a resolver must
|
|
661
|
+
// be an output type resolver with a non-suspended, non-null value to
|
|
662
|
+
// refernce any output type record ids.
|
|
663
|
+
RelayModernRecord.setValue(
|
|
664
|
+
resolverRecord,
|
|
665
|
+
RELAY_RESOLVER_OUTPUT_TYPE_RECORD_IDS,
|
|
666
|
+
new Set(),
|
|
667
|
+
);
|
|
633
668
|
}
|
|
634
669
|
|
|
635
670
|
return updatedDataIDs;
|
|
@@ -639,7 +674,7 @@ class LiveResolverCache implements ResolverCache {
|
|
|
639
674
|
this._store.__notifyUpdatedSubscribers(updatedDataIDs);
|
|
640
675
|
}
|
|
641
676
|
|
|
642
|
-
_getResolverValue(resolverRecord: Record):
|
|
677
|
+
_getResolverValue(resolverRecord: Record): unknown {
|
|
643
678
|
return RelayModernRecord.getValue(resolverRecord, RELAY_RESOLVER_VALUE_KEY);
|
|
644
679
|
}
|
|
645
680
|
|
|
@@ -659,9 +694,9 @@ class LiveResolverCache implements ResolverCache {
|
|
|
659
694
|
const recordID: string = recordsToVisit.pop();
|
|
660
695
|
visited.add(recordID);
|
|
661
696
|
|
|
662
|
-
// $FlowFixMe[incompatible-
|
|
697
|
+
// $FlowFixMe[incompatible-type]
|
|
663
698
|
updatedDataIDs.add(recordID);
|
|
664
|
-
// $FlowFixMe[incompatible-
|
|
699
|
+
// $FlowFixMe[incompatible-type]
|
|
665
700
|
const fragmentSet = this._recordIDToResolverIDs.get(recordID);
|
|
666
701
|
if (fragmentSet == null) {
|
|
667
702
|
continue;
|
|
@@ -737,7 +772,7 @@ class LiveResolverCache implements ResolverCache {
|
|
|
737
772
|
// containing only "weak" records.
|
|
738
773
|
_normalizeOutputTypeValue(
|
|
739
774
|
outputTypeDataID: DataID,
|
|
740
|
-
value: {
|
|
775
|
+
value: {readonly [key: string]: unknown},
|
|
741
776
|
variables: Variables,
|
|
742
777
|
normalizationInfo: ResolverNormalizationInfo,
|
|
743
778
|
fieldPath: Array<string>,
|
|
@@ -788,7 +823,7 @@ class LiveResolverCache implements ResolverCache {
|
|
|
788
823
|
return source;
|
|
789
824
|
}
|
|
790
825
|
default:
|
|
791
|
-
|
|
826
|
+
normalizationInfo.kind as empty;
|
|
792
827
|
invariant(
|
|
793
828
|
false,
|
|
794
829
|
'LiveResolverCache: Unexpected normalization info kind `%s`.',
|
|
@@ -846,7 +881,7 @@ class LiveResolverCache implements ResolverCache {
|
|
|
846
881
|
function updateCurrentSource(
|
|
847
882
|
currentSource: MutableRecordSource,
|
|
848
883
|
nextSource: RecordSource,
|
|
849
|
-
prevOutputTypeRecordIDs:
|
|
884
|
+
prevOutputTypeRecordIDs: ?ReadonlySet<DataID>,
|
|
850
885
|
): DataIDSet {
|
|
851
886
|
const updatedDataIDs = new Set<DataID>();
|
|
852
887
|
|
|
@@ -944,7 +979,7 @@ function markInvalidatedLinkedResolverRecords(
|
|
|
944
979
|
|
|
945
980
|
function unsubscribeFromLiveResolverRecordsImpl(
|
|
946
981
|
recordSource: RecordSource,
|
|
947
|
-
invalidatedDataIDs:
|
|
982
|
+
invalidatedDataIDs: ReadonlySet<DataID>,
|
|
948
983
|
): void {
|
|
949
984
|
if (invalidatedDataIDs.size === 0) {
|
|
950
985
|
return;
|
|
@@ -999,7 +1034,7 @@ function getConcreteTypename(
|
|
|
999
1034
|
const typename =
|
|
1000
1035
|
normalizationInfo.concreteType ??
|
|
1001
1036
|
// $FlowFixMe[prop-missing]
|
|
1002
|
-
(currentValue.__typename
|
|
1037
|
+
(currentValue.__typename as string);
|
|
1003
1038
|
invariant(
|
|
1004
1039
|
typename != null,
|
|
1005
1040
|
'normalizationInfo.concreteType should not be null, or the value returned from the resolver should include a __typename field, ' +
|
|
@@ -1010,6 +1045,6 @@ function getConcreteTypename(
|
|
|
1010
1045
|
|
|
1011
1046
|
module.exports = {
|
|
1012
1047
|
LiveResolverCache,
|
|
1013
|
-
getUpdatedDataIDs,
|
|
1014
1048
|
RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY,
|
|
1049
|
+
getUpdatedDataIDs,
|
|
1015
1050
|
};
|
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
const LIVE_RESOLVER_SUSPENSE_SENTINEL:
|
|
14
|
+
const LIVE_RESOLVER_SUSPENSE_SENTINEL: unknown = Object.freeze({
|
|
15
15
|
__LIVE_RESOLVER_SUSPENSE_SENTINEL: true,
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
function suspenseSentinel(): empty {
|
|
19
|
-
// $FlowFixMe[incompatible-
|
|
19
|
+
// $FlowFixMe[incompatible-type]
|
|
20
20
|
return LIVE_RESOLVER_SUSPENSE_SENTINEL;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function isSuspenseSentinel(value:
|
|
23
|
+
function isSuspenseSentinel(value: unknown): boolean {
|
|
24
24
|
return value === LIVE_RESOLVER_SUSPENSE_SENTINEL;
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -18,7 +18,7 @@ const RelayModernRecord = require('../RelayModernRecord');
|
|
|
18
18
|
const {RELAY_RESOLVER_OUTPUT_TYPE_RECORD_IDS} = require('../RelayStoreUtils');
|
|
19
19
|
const invariant = require('invariant');
|
|
20
20
|
|
|
21
|
-
function getOutputTypeRecordIDs(record: Record):
|
|
21
|
+
function getOutputTypeRecordIDs(record: Record): ReadonlySet<DataID> | null {
|
|
22
22
|
const maybeOutputTypeRecordIDs = RelayModernRecord.getValue(
|
|
23
23
|
record,
|
|
24
24
|
RELAY_RESOLVER_OUTPUT_TYPE_RECORD_IDS,
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
import type {LiveState} from '../RelayStoreTypes';
|
|
15
15
|
|
|
16
|
-
declare function isLiveStateValue<T, U = LiveState<T>>(v:
|
|
16
|
+
declare function isLiveStateValue<T, U = LiveState<T>>(v: unknown): v is U;
|
|
17
17
|
|
|
18
|
-
function isLiveStateValue(v:
|
|
18
|
+
function isLiveStateValue(v: unknown) {
|
|
19
19
|
return (
|
|
20
20
|
v != null &&
|
|
21
21
|
typeof v === 'object' &&
|
|
@@ -0,0 +1,27 @@
|
|
|
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 type { GraphQLTaggedNode } from '../../query/GraphQLTag';
|
|
9
|
+
import type { FragmentType } from '../RelayStoreTypes';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This a higher order function that returns a relay resolver that can read the data for
|
|
13
|
+
* the fragment`.
|
|
14
|
+
*
|
|
15
|
+
* - fragment: contains fragment Reader AST with resolver's data dependencies.
|
|
16
|
+
* - resolverFn: original resolver function that expects a data from the fragment
|
|
17
|
+
* - (optional) fieldName: individual field that needs to be read out of the fragment.
|
|
18
|
+
*
|
|
19
|
+
* This will not call the `resolverFn` if the fragment data for it is null/undefined.
|
|
20
|
+
* The compiler generates calls to this function, ensuring the correct set of arguments.
|
|
21
|
+
*/
|
|
22
|
+
export function resolverDataInjector(
|
|
23
|
+
fragment: GraphQLTaggedNode,
|
|
24
|
+
_resolverFn: unknown,
|
|
25
|
+
fieldName?: string,
|
|
26
|
+
isRequiredField?: boolean,
|
|
27
|
+
): (fragmentKey: FragmentType, args: unknown) => unknown;
|
|
@@ -17,7 +17,7 @@ import type {FragmentType, ResolverContext} from '../RelayStoreTypes';
|
|
|
17
17
|
const {readFragment} = require('../ResolverFragments');
|
|
18
18
|
const invariant = require('invariant');
|
|
19
19
|
|
|
20
|
-
type ResolverFn = ($FlowFixMe, ?$FlowFixMe, ResolverContext) =>
|
|
20
|
+
type ResolverFn = ($FlowFixMe, ?$FlowFixMe, ResolverContext) => unknown;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
@@ -31,20 +31,23 @@ type ResolverFn = ($FlowFixMe, ?$FlowFixMe, ResolverContext) => mixed;
|
|
|
31
31
|
* This will not call the `resolverFn` if the fragment data for it is null/undefined.
|
|
32
32
|
* The the compiler generates calls to this function, ensuring the correct set of arguments.
|
|
33
33
|
*/
|
|
34
|
-
function resolverDataInjector<
|
|
34
|
+
function resolverDataInjector<
|
|
35
|
+
TFragmentType extends FragmentType,
|
|
36
|
+
TData extends ?{...},
|
|
37
|
+
>(
|
|
35
38
|
fragment: Fragment<TFragmentType, TData>,
|
|
36
39
|
// Resolvers have their own type assertions, we don't want to confuse users
|
|
37
40
|
// with a type error in their generated code at this point.
|
|
38
41
|
_resolverFn: $FlowFixMe,
|
|
39
42
|
fieldName?: string,
|
|
40
43
|
isRequiredField?: boolean,
|
|
41
|
-
): (fragmentKey: TFragmentType, args:
|
|
44
|
+
): (fragmentKey: TFragmentType, args: unknown) => unknown {
|
|
42
45
|
const resolverFn: ResolverFn = _resolverFn;
|
|
43
46
|
return (
|
|
44
47
|
fragmentKey: TFragmentType,
|
|
45
|
-
args:
|
|
48
|
+
args: unknown,
|
|
46
49
|
resolverContext: ResolverContext,
|
|
47
|
-
):
|
|
50
|
+
): unknown => {
|
|
48
51
|
const data = readFragment(fragment, fragmentKey);
|
|
49
52
|
if (fieldName != null) {
|
|
50
53
|
if (data == null) {
|
|
@@ -0,0 +1,46 @@
|
|
|
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 type { RelayObservable as Observable } from '../network/RelayObservable';
|
|
9
|
+
import type { GraphQLTaggedNode } from '../query/GraphQLTag';
|
|
10
|
+
import type {ArrayKeyType, ArrayKeyTypeData, Environment as IEnvironment, FragmentState, KeyType, KeyTypeData} from './RelayStoreTypes';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* EXPERIMENTAL: This API is experimental and does not yet support all Relay
|
|
14
|
+
* features. Notably, it does not correctly handle some features of Relay Resolvers.
|
|
15
|
+
*
|
|
16
|
+
* Given a fragment and a fragment reference, returns an observable that emits
|
|
17
|
+
* the state of the fragment over time. The observable will emit the following
|
|
18
|
+
* values:
|
|
19
|
+
* - 'ok': The fragment has a value
|
|
20
|
+
* - 'error': The fragment has an error, this could be due to a network error or
|
|
21
|
+
* a field error due to @required(action: THROW) or @throwOnFieldError
|
|
22
|
+
* - 'loading': The fragment is still in flight and is still expected to resolver.
|
|
23
|
+
*/
|
|
24
|
+
export function observeFragment<TKey extends KeyType>(
|
|
25
|
+
environment: IEnvironment,
|
|
26
|
+
fragmentInput: GraphQLTaggedNode,
|
|
27
|
+
fragmentRef: TKey,
|
|
28
|
+
): Observable<FragmentState<KeyTypeData<TKey>>>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* EXPERIMENTAL: This API is experimental and does not yet support all Relay
|
|
32
|
+
* features. Notably, it does not correctly handle some features of Relay Resolvers.
|
|
33
|
+
*
|
|
34
|
+
* Given a fragment and a fragment reference, returns an observable that emits
|
|
35
|
+
* the state of the fragment over time. The observable will emit the following
|
|
36
|
+
* values:
|
|
37
|
+
* - 'ok': The fragment has a value
|
|
38
|
+
* - 'error': The fragment has an error, this could be due to a network error or
|
|
39
|
+
* a field error due to @required(action: THROW) or @throwOnFieldError
|
|
40
|
+
* - 'loading': The fragment is still in flight and is still expected to resolver.
|
|
41
|
+
*/
|
|
42
|
+
export function observeFragment<TKey extends ArrayKeyType>(
|
|
43
|
+
environment: IEnvironment,
|
|
44
|
+
fragmentInput: GraphQLTaggedNode,
|
|
45
|
+
fragmentRef: TKey,
|
|
46
|
+
): Observable<FragmentState<ArrayKeyTypeData<TKey>>>;
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
* @oncall relay
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
PluralReaderSelector,
|
|
14
|
+
ReaderSelector,
|
|
15
|
+
RequestDescriptor,
|
|
16
|
+
} from './RelayStoreTypes';
|
|
13
17
|
import type {
|
|
14
18
|
Fragment,
|
|
15
19
|
FragmentType,
|
|
@@ -41,7 +45,7 @@ export type FragmentState<T> =
|
|
|
41
45
|
| {state: 'loading'};
|
|
42
46
|
|
|
43
47
|
export type HasSpread<TFragmentType> = {
|
|
44
|
-
|
|
48
|
+
readonly $fragmentSpreads: TFragmentType,
|
|
45
49
|
...
|
|
46
50
|
};
|
|
47
51
|
|
|
@@ -59,12 +63,12 @@ export type HasSpread<TFragmentType> = {
|
|
|
59
63
|
* you might choose to @defer a fragment that you only need to access inside an
|
|
60
64
|
* event handler and then await its value inside the handler if/when it is triggered.
|
|
61
65
|
*/
|
|
62
|
-
async function waitForFragmentData<TFragmentType
|
|
66
|
+
async function waitForFragmentData<TFragmentType extends FragmentType, TData>(
|
|
63
67
|
environment: IEnvironment,
|
|
64
68
|
fragment: Fragment<TFragmentType, TData>,
|
|
65
69
|
fragmentRef:
|
|
66
70
|
| HasSpread<TFragmentType>
|
|
67
|
-
|
|
|
71
|
+
| ReadonlyArray<HasSpread<TFragmentType>>,
|
|
68
72
|
): Promise<TData> {
|
|
69
73
|
let subscription: ?Subscription;
|
|
70
74
|
|
|
@@ -86,18 +90,18 @@ async function waitForFragmentData<TFragmentType: FragmentType, TData>(
|
|
|
86
90
|
});
|
|
87
91
|
subscription?.unsubscribe();
|
|
88
92
|
return data;
|
|
89
|
-
} catch (e:
|
|
93
|
+
} catch (e: unknown) {
|
|
90
94
|
subscription?.unsubscribe();
|
|
91
95
|
throw e;
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
|
|
95
|
-
declare function observeFragment<TFragmentType
|
|
99
|
+
declare function observeFragment<TFragmentType extends FragmentType, TData>(
|
|
96
100
|
environment: IEnvironment,
|
|
97
101
|
fragment: Fragment<TFragmentType, TData>,
|
|
98
102
|
fragmentRef:
|
|
99
103
|
| HasSpread<TFragmentType>
|
|
100
|
-
|
|
|
104
|
+
| ReadonlyArray<HasSpread<TFragmentType>>,
|
|
101
105
|
): Observable<FragmentState<TData>>;
|
|
102
106
|
|
|
103
107
|
/**
|
|
@@ -112,25 +116,28 @@ declare function observeFragment<TFragmentType: FragmentType, TData>(
|
|
|
112
116
|
* a field error due to @required(action: THROW) or @throwOnFieldError
|
|
113
117
|
* - 'loading': The fragment is still in flight and is still expected to resolver.
|
|
114
118
|
*/
|
|
115
|
-
function observeFragment<TFragmentType
|
|
119
|
+
function observeFragment<TFragmentType extends FragmentType, TData>(
|
|
116
120
|
environment: IEnvironment,
|
|
117
121
|
fragment: Fragment<TFragmentType, TData>,
|
|
118
|
-
fragmentRef:
|
|
119
|
-
):
|
|
122
|
+
fragmentRef: unknown,
|
|
123
|
+
): unknown {
|
|
120
124
|
const fragmentNode = getFragment(fragment);
|
|
121
125
|
const fragmentSelector = getSelector(fragmentNode, fragmentRef);
|
|
126
|
+
|
|
127
|
+
invariant(fragmentSelector != null, 'Expected a selector, got null.');
|
|
128
|
+
|
|
122
129
|
invariant(
|
|
123
|
-
fragmentNode.metadata?.hasClientEdges == null
|
|
130
|
+
fragmentNode.metadata?.hasClientEdges == null ||
|
|
131
|
+
fragmentSelectorUsesExecTimeResolver(fragmentSelector),
|
|
124
132
|
"Client edges aren't supported yet.",
|
|
125
133
|
);
|
|
126
|
-
invariant(fragmentSelector != null, 'Expected a selector, got null.');
|
|
127
134
|
switch (fragmentSelector.kind) {
|
|
128
135
|
case 'SingularReaderSelector':
|
|
129
136
|
return observeSingularSelector(environment, fragment, fragmentSelector);
|
|
130
137
|
case 'PluralReaderSelector': {
|
|
131
138
|
return observePluralSelector(
|
|
132
139
|
environment,
|
|
133
|
-
|
|
140
|
+
fragment as $FlowFixMe,
|
|
134
141
|
fragmentSelector,
|
|
135
142
|
);
|
|
136
143
|
}
|
|
@@ -138,7 +145,29 @@ function observeFragment<TFragmentType: FragmentType, TData>(
|
|
|
138
145
|
invariant(false, 'Unsupported fragment selector kind');
|
|
139
146
|
}
|
|
140
147
|
|
|
141
|
-
function
|
|
148
|
+
function fragmentSelectorUsesExecTimeResolver(
|
|
149
|
+
fragmentSelector: ReaderSelector,
|
|
150
|
+
) {
|
|
151
|
+
switch (fragmentSelector?.kind) {
|
|
152
|
+
case 'SingularReaderSelector':
|
|
153
|
+
return (
|
|
154
|
+
(fragmentSelector.owner.node.operation?.use_exec_time_resolvers ??
|
|
155
|
+
fragmentSelector.owner.node.operation?.exec_time_resolvers_enabled_provider?.get()) ===
|
|
156
|
+
true
|
|
157
|
+
);
|
|
158
|
+
case 'PluralReaderSelector': {
|
|
159
|
+
return fragmentSelector.selectors?.every(
|
|
160
|
+
selector =>
|
|
161
|
+
(selector.owner.node.operation.use_exec_time_resolvers ??
|
|
162
|
+
selector.owner.node.operation?.exec_time_resolvers_enabled_provider?.get()) ===
|
|
163
|
+
true,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function observeSingularSelector<TFragmentType extends FragmentType, TData>(
|
|
142
171
|
environment: IEnvironment,
|
|
143
172
|
fragmentNode: Fragment<TFragmentType, TData>,
|
|
144
173
|
fragmentSelector: SingularReaderSelector,
|
|
@@ -171,8 +200,8 @@ function observeSingularSelector<TFragmentType: FragmentType, TData>(
|
|
|
171
200
|
}
|
|
172
201
|
|
|
173
202
|
function observePluralSelector<
|
|
174
|
-
TFragmentType
|
|
175
|
-
TData
|
|
203
|
+
TFragmentType extends FragmentType,
|
|
204
|
+
TData extends Array<unknown>,
|
|
176
205
|
>(
|
|
177
206
|
environment: IEnvironment,
|
|
178
207
|
fragmentNode: Fragment<TFragmentType, TData>,
|
|
@@ -193,7 +222,7 @@ function observePluralSelector<
|
|
|
193
222
|
),
|
|
194
223
|
);
|
|
195
224
|
|
|
196
|
-
sink.next(
|
|
225
|
+
sink.next(mergeFragmentStates(states) as $FlowFixMe);
|
|
197
226
|
|
|
198
227
|
const subscriptions = snapshots.map((snapshot, index) =>
|
|
199
228
|
environment.subscribe(snapshot, latestSnapshot => {
|
|
@@ -205,7 +234,7 @@ function observePluralSelector<
|
|
|
205
234
|
);
|
|
206
235
|
// This doesn't batch updates, so it will notify the subscriber multiple times
|
|
207
236
|
// if a store update impacting multiple items in the list is published.
|
|
208
|
-
sink.next(
|
|
237
|
+
sink.next(mergeFragmentStates(states) as $FlowFixMe);
|
|
209
238
|
}),
|
|
210
239
|
);
|
|
211
240
|
|
|
@@ -213,7 +242,7 @@ function observePluralSelector<
|
|
|
213
242
|
});
|
|
214
243
|
}
|
|
215
244
|
|
|
216
|
-
function snapshotToFragmentState<TFragmentType
|
|
245
|
+
function snapshotToFragmentState<TFragmentType extends FragmentType, TData>(
|
|
217
246
|
environment: IEnvironment,
|
|
218
247
|
fragmentNode: Fragment<TFragmentType, TData>,
|
|
219
248
|
owner: RequestDescriptor,
|
|
@@ -266,11 +295,11 @@ function snapshotToFragmentState<TFragmentType: FragmentType, TData>(
|
|
|
266
295
|
|
|
267
296
|
invariant(snapshot.data != null, 'Expected data to be non-null.');
|
|
268
297
|
|
|
269
|
-
return {state: 'ok', value:
|
|
298
|
+
return {state: 'ok', value: snapshot.data as $FlowFixMe};
|
|
270
299
|
}
|
|
271
300
|
|
|
272
301
|
function mergeFragmentStates<T>(
|
|
273
|
-
states:
|
|
302
|
+
states: ReadonlyArray<FragmentState<T>>,
|
|
274
303
|
): FragmentState<Array<T>> {
|
|
275
304
|
const value = [];
|
|
276
305
|
for (const state of states) {
|
|
@@ -0,0 +1,30 @@
|
|
|
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 type { RelayObservable as Observable } from '../network/RelayObservable';
|
|
9
|
+
import type { GraphQLTaggedNode } from '../query/GraphQLTag';
|
|
10
|
+
import type { OperationType } from '../util/RelayRuntimeTypes';
|
|
11
|
+
import type {Environment as IEnvironment, FragmentState} from './RelayStoreTypes';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This function returns an observable that can be used to subscribe to the data
|
|
15
|
+
* contained in a query. It does not return the full response shape, but rather
|
|
16
|
+
* the contents of the query body minus any fragment spreads. If you wish to
|
|
17
|
+
* read the contents of a fragment spread into this query you may pass the
|
|
18
|
+
* object into which the fragment was spread to `observeFragment`.
|
|
19
|
+
*
|
|
20
|
+
* NOTE: `observeQuery` assumes that you have already fetched and retained the
|
|
21
|
+
* query via some other means, such as `fetchQuery`.
|
|
22
|
+
*
|
|
23
|
+
* This feature is still experimental and does not properly handle some resolver
|
|
24
|
+
* features such as client-to-server edges.
|
|
25
|
+
*/
|
|
26
|
+
export function observeQuery<T extends OperationType>(
|
|
27
|
+
environment: IEnvironment,
|
|
28
|
+
gqlQuery: GraphQLTaggedNode,
|
|
29
|
+
variables: T['variables'],
|
|
30
|
+
): Observable<FragmentState<T['response']>>;
|
|
@@ -32,7 +32,7 @@ const {createOperationDescriptor} = require('./RelayModernOperationDescriptor');
|
|
|
32
32
|
* This feature is still experimental and does not properly handle some resolver
|
|
33
33
|
* features such as client-to-server edges.
|
|
34
34
|
*/
|
|
35
|
-
function observeQuery<TVariables
|
|
35
|
+
function observeQuery<TVariables extends Variables, TData>(
|
|
36
36
|
environment: IEnvironment,
|
|
37
37
|
gqlQuery: Query<TVariables, TData>,
|
|
38
38
|
variables: TVariables,
|
|
@@ -43,15 +43,15 @@ function observeQuery<TVariables: Variables, TData>(
|
|
|
43
43
|
);
|
|
44
44
|
|
|
45
45
|
const rootFragmentRef: $FlowFixMe = {
|
|
46
|
-
|
|
46
|
+
__fragmentOwner: operation.request,
|
|
47
47
|
__fragments: {
|
|
48
48
|
[operation.fragment.node.name]: operation.request.variables,
|
|
49
49
|
},
|
|
50
|
-
|
|
50
|
+
__id: operation.fragment.dataID,
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
const fragmentNode: Fragment<$FlowFixMe, TData> =
|
|
54
|
-
.fragment
|
|
53
|
+
const fragmentNode: Fragment<$FlowFixMe, TData> = operation.request.node
|
|
54
|
+
.fragment as $FlowFixMe;
|
|
55
55
|
|
|
56
56
|
return observeFragment(environment, fragmentNode, rootFragmentRef);
|
|
57
57
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 type { GraphQLTaggedNode } from '../query/GraphQLTag';
|
|
9
|
+
import type {KeyType, KeyTypeData} from './RelayStoreTypes';
|
|
10
|
+
|
|
11
|
+
export function readInlineData<TKey extends KeyType>(
|
|
12
|
+
fragmentInput: GraphQLTaggedNode,
|
|
13
|
+
fragmentRef: TKey,
|
|
14
|
+
): KeyTypeData<TKey>;
|
|
15
|
+
|
|
16
|
+
export function readInlineData<TKey extends KeyType>(
|
|
17
|
+
fragmentInput: GraphQLTaggedNode,
|
|
18
|
+
fragmentRef: TKey | null | undefined,
|
|
19
|
+
): KeyTypeData<TKey> | null | undefined;
|
|
@@ -20,26 +20,26 @@ const {FRAGMENTS_KEY} = require('./RelayStoreUtils');
|
|
|
20
20
|
const invariant = require('invariant');
|
|
21
21
|
|
|
22
22
|
type HasSpread<TFragmentType> = {
|
|
23
|
-
|
|
23
|
+
readonly $fragmentSpreads: TFragmentType,
|
|
24
24
|
...
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Reads an @inline data fragment that was spread into the parent fragment.
|
|
29
29
|
*/
|
|
30
|
-
declare function readInlineData<TFragmentType
|
|
30
|
+
declare function readInlineData<TFragmentType extends FragmentType, TData>(
|
|
31
31
|
fragment: InlineFragment<TFragmentType, TData>,
|
|
32
32
|
key: HasSpread<TFragmentType>,
|
|
33
33
|
): TData;
|
|
34
|
-
declare function readInlineData<TFragmentType
|
|
34
|
+
declare function readInlineData<TFragmentType extends FragmentType, TData>(
|
|
35
35
|
fragment: InlineFragment<TFragmentType, TData>,
|
|
36
36
|
key: ?HasSpread<TFragmentType>,
|
|
37
37
|
): ?TData;
|
|
38
38
|
|
|
39
39
|
function readInlineData(
|
|
40
40
|
fragment: GraphQLTaggedNode,
|
|
41
|
-
fragmentRef:
|
|
42
|
-
):
|
|
41
|
+
fragmentRef: unknown,
|
|
42
|
+
): unknown {
|
|
43
43
|
const inlineDataFragment = getInlineDataFragment(fragment);
|
|
44
44
|
if (fragmentRef == null) {
|
|
45
45
|
return fragmentRef;
|