relay-runtime 20.1.0 → 21.0.0
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.js +1 -1
- package/experimental.js.flow +8 -8
- package/handlers/connection/ConnectionHandler.js.flow +5 -5
- package/handlers/connection/ConnectionInterface.js.flow +1 -1
- 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 +113 -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 +82 -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 +213 -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 +66 -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.js.flow +2 -2
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +7 -7
- package/multi-actor-environment/ActorUtils.js.flow +1 -1
- package/multi-actor-environment/MultiActorEnvironment.js.flow +12 -8
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +3 -3
- 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.js.flow +2 -2
- package/mutations/commitMutation.js.flow +20 -16
- 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/RelayNetworkTypes.js.flow +4 -4
- package/network/RelayObservable.js.flow +16 -14
- package/network/RelayQueryResponseCache.js.flow +3 -3
- package/network/wrapNetworkWithLogObserver.js.flow +1 -1
- package/package.json +2 -1
- package/query/GraphQLTag.js.flow +22 -10
- package/query/fetchQuery.js.flow +23 -10
- package/query/fetchQuery_DEPRECATED.js.flow +1 -1
- package/store/DataChecker.js.flow +43 -9
- package/store/NormalizationEngine.js.flow +779 -0
- package/store/OperationExecutor.js.flow +173 -70
- 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.js.flow +41 -26
- package/store/RelayModernFragmentSpecResolver.js.flow +1 -1
- package/store/RelayModernOperationDescriptor.js.flow +1 -1
- package/store/RelayModernRecord.js.flow +46 -22
- package/store/RelayModernSelector.js.flow +21 -21
- package/store/RelayModernStore.js.flow +219 -58
- package/store/RelayOperationTracker.js.flow +2 -2
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +21 -12
- package/store/RelayReader.js.flow +130 -58
- package/store/RelayRecordSource.js.flow +10 -0
- package/store/RelayRecordState.js.flow +1 -1
- package/store/RelayReferenceMarker.js.flow +5 -4
- package/store/RelayResponseNormalizer.js.flow +130 -54
- package/store/RelayStoreSubscriptions.js.flow +52 -8
- package/store/RelayStoreTypes.js.flow +153 -64
- package/store/RelayStoreUtils.js.flow +15 -7
- package/store/ResolverCache.js.flow +2 -2
- package/store/ResolverFragments.js.flow +12 -12
- package/store/StoreInspector.js.flow +6 -7
- package/store/cloneRelayHandleSourceField.js.flow +1 -1
- package/store/cloneRelayScalarHandleSourceField.js.flow +1 -1
- package/store/createRelayContext.js.flow +1 -1
- package/store/createRelayLoggingContext.js.flow +4 -4
- package/store/defaultGetDataID.js.flow +2 -2
- 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.js.flow +8 -5
- package/store/observeFragmentExperimental.js.flow +49 -20
- package/store/observeQueryExperimental.js.flow +5 -5
- package/store/readInlineData.js.flow +4 -4
- package/store/waitForFragmentExperimental.js.flow +3 -3
- package/subscription/requestSubscription.js.flow +7 -7
- package/util/NormalizationNode.js.flow +34 -32
- package/util/ReaderNode.js.flow +32 -30
- package/util/RelayConcreteNode.js.flow +5 -5
- package/util/RelayError.js.flow +4 -1
- package/util/RelayFeatureFlags.js.flow +21 -1
- package/util/RelayProfiler.js.flow +1 -1
- package/util/RelayReplaySubject.js.flow +3 -3
- package/util/RelayRuntimeTypes.js.flow +11 -11
- package/util/createPayloadFor3DField.js.flow +9 -5
- package/util/deepFreeze.js.flow +2 -2
- package/util/getFragmentIdentifier.js.flow +1 -1
- package/util/getPaginationMetadata.js.flow +1 -1
- package/util/getPaginationVariables.js.flow +1 -1
- package/util/getPendingOperationsForFragment.js.flow +2 -2
- package/util/getRefetchMetadata.js.flow +6 -5
- package/util/getValueAtPath.js.flow +3 -3
- package/util/handlePotentialSnapshotErrors.js.flow +5 -5
- package/util/isEmptyObject.js.flow +1 -1
- package/util/isPromise.js.flow +2 -2
- package/util/isScalarAndEqual.js.flow +1 -1
- package/util/recycleNodesInto.js.flow +2 -2
- package/util/registerEnvironmentWithDevTools.js.flow +1 -1
- package/util/shallowFreeze.js.flow +1 -1
- package/util/stableCopy.js.flow +5 -5
- package/util/withProvidedVariables.js.flow +14 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "relay-runtime",
|
|
3
3
|
"description": "A core runtime for building GraphQL-driven applications.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "21.0.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"relay"
|
|
@@ -23,5 +23,6 @@
|
|
|
23
23
|
"": "./"
|
|
24
24
|
},
|
|
25
25
|
"main": "index.js",
|
|
26
|
+
"types": "index.d.ts",
|
|
26
27
|
"haste_commonjs": true
|
|
27
28
|
}
|
package/query/GraphQLTag.js.flow
CHANGED
|
@@ -46,7 +46,7 @@ export type GraphQLTaggedNode =
|
|
|
46
46
|
* Runtime function to correspond to the `graphql` tagged template function.
|
|
47
47
|
* All calls to this function should be transformed by the plugin.
|
|
48
48
|
*/
|
|
49
|
-
function graphql(strings:
|
|
49
|
+
function graphql(strings: ReadonlyArray<string>): any {
|
|
50
50
|
invariant(
|
|
51
51
|
false,
|
|
52
52
|
'graphql: Unexpected invocation at runtime. Either the Babel transform ' +
|
|
@@ -65,7 +65,7 @@ function getNode(
|
|
|
65
65
|
| ConcreteUpdatableQuery {
|
|
66
66
|
let node = taggedNode;
|
|
67
67
|
if (typeof node === 'function') {
|
|
68
|
-
node =
|
|
68
|
+
node = node() as ReaderFragment | ConcreteRequest;
|
|
69
69
|
warning(
|
|
70
70
|
false,
|
|
71
71
|
'RelayGraphQLTag: node `%s` unexpectedly wrapped in a function.',
|
|
@@ -82,6 +82,8 @@ function isFragment(node: GraphQLTaggedNode): boolean {
|
|
|
82
82
|
const fragment = getNode(node);
|
|
83
83
|
return (
|
|
84
84
|
typeof fragment === 'object' &&
|
|
85
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
86
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
85
87
|
fragment !== null &&
|
|
86
88
|
fragment.kind === RelayConcreteNode.FRAGMENT
|
|
87
89
|
);
|
|
@@ -91,6 +93,8 @@ function isRequest(node: GraphQLTaggedNode): boolean {
|
|
|
91
93
|
const request = getNode(node);
|
|
92
94
|
return (
|
|
93
95
|
typeof request === 'object' &&
|
|
96
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
97
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
94
98
|
request !== null &&
|
|
95
99
|
request.kind === RelayConcreteNode.REQUEST
|
|
96
100
|
);
|
|
@@ -100,6 +104,8 @@ function isUpdatableQuery(node: GraphQLTaggedNode): boolean {
|
|
|
100
104
|
const updatableQuery = getNode(node);
|
|
101
105
|
return (
|
|
102
106
|
typeof updatableQuery === 'object' &&
|
|
107
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
108
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
103
109
|
updatableQuery !== null &&
|
|
104
110
|
updatableQuery.kind === RelayConcreteNode.UPDATABLE_QUERY
|
|
105
111
|
);
|
|
@@ -109,6 +115,8 @@ function isInlineDataFragment(node: GraphQLTaggedNode): boolean {
|
|
|
109
115
|
const fragment = getNode(node);
|
|
110
116
|
return (
|
|
111
117
|
typeof fragment === 'object' &&
|
|
118
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
119
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
112
120
|
fragment !== null &&
|
|
113
121
|
fragment.kind === RelayConcreteNode.INLINE_DATA_FRAGMENT
|
|
114
122
|
);
|
|
@@ -121,7 +129,7 @@ function getFragment(taggedNode: GraphQLTaggedNode): ReaderFragment {
|
|
|
121
129
|
'GraphQLTag: Expected a fragment, got `%s`.',
|
|
122
130
|
JSON.stringify(fragment),
|
|
123
131
|
);
|
|
124
|
-
return
|
|
132
|
+
return fragment as any;
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
function getPaginationFragment(
|
|
@@ -131,6 +139,8 @@ function getPaginationFragment(
|
|
|
131
139
|
const refetch = fragment.metadata?.refetch;
|
|
132
140
|
const connection = refetch?.connection;
|
|
133
141
|
if (
|
|
142
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
143
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
134
144
|
refetch === null ||
|
|
135
145
|
typeof refetch !== 'object' ||
|
|
136
146
|
connection === null ||
|
|
@@ -138,7 +148,7 @@ function getPaginationFragment(
|
|
|
138
148
|
) {
|
|
139
149
|
return null;
|
|
140
150
|
}
|
|
141
|
-
return
|
|
151
|
+
return fragment as any;
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
function getRefetchableFragment(
|
|
@@ -146,10 +156,12 @@ function getRefetchableFragment(
|
|
|
146
156
|
): ReaderRefetchableFragment | null {
|
|
147
157
|
const fragment = getFragment(taggedNode);
|
|
148
158
|
const refetch = fragment.metadata?.refetch;
|
|
159
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
160
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
149
161
|
if (refetch === null || typeof refetch !== 'object') {
|
|
150
162
|
return null;
|
|
151
163
|
}
|
|
152
|
-
return
|
|
164
|
+
return fragment as any;
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
function getRequest(taggedNode: GraphQLTaggedNode): ConcreteRequest {
|
|
@@ -159,7 +171,7 @@ function getRequest(taggedNode: GraphQLTaggedNode): ConcreteRequest {
|
|
|
159
171
|
'GraphQLTag: Expected a request, got `%s`.',
|
|
160
172
|
JSON.stringify(request),
|
|
161
173
|
);
|
|
162
|
-
return
|
|
174
|
+
return request as any;
|
|
163
175
|
}
|
|
164
176
|
|
|
165
177
|
function getUpdatableQuery(
|
|
@@ -171,7 +183,7 @@ function getUpdatableQuery(
|
|
|
171
183
|
'GraphQLTag: Expected a request, got `%s`.',
|
|
172
184
|
JSON.stringify(updatableQuery),
|
|
173
185
|
);
|
|
174
|
-
return
|
|
186
|
+
return updatableQuery as any;
|
|
175
187
|
}
|
|
176
188
|
|
|
177
189
|
function getInlineDataFragment(
|
|
@@ -183,20 +195,20 @@ function getInlineDataFragment(
|
|
|
183
195
|
'GraphQLTag: Expected an inline data fragment, got `%s`.',
|
|
184
196
|
JSON.stringify(fragment),
|
|
185
197
|
);
|
|
186
|
-
return
|
|
198
|
+
return fragment as any;
|
|
187
199
|
}
|
|
188
200
|
|
|
189
201
|
module.exports = {
|
|
190
202
|
getFragment,
|
|
203
|
+
getInlineDataFragment,
|
|
191
204
|
getNode,
|
|
192
205
|
getPaginationFragment,
|
|
193
206
|
getRefetchableFragment,
|
|
194
207
|
getRequest,
|
|
195
208
|
getUpdatableQuery,
|
|
196
|
-
getInlineDataFragment,
|
|
197
209
|
graphql,
|
|
198
210
|
isFragment,
|
|
211
|
+
isInlineDataFragment,
|
|
199
212
|
isRequest,
|
|
200
213
|
isUpdatableQuery,
|
|
201
|
-
isInlineDataFragment,
|
|
202
214
|
};
|
package/query/fetchQuery.js.flow
CHANGED
|
@@ -112,11 +112,11 @@ const invariant = require('invariant');
|
|
|
112
112
|
* ```
|
|
113
113
|
* NOTE: When using .toPromise(), the request cannot be cancelled.
|
|
114
114
|
*/
|
|
115
|
-
function fetchQuery<TVariables
|
|
115
|
+
function fetchQuery<TVariables extends Variables, TData, TRawResponse>(
|
|
116
116
|
environment: IEnvironment,
|
|
117
117
|
query: Query<TVariables, TData, TRawResponse>,
|
|
118
118
|
variables: NoInfer<TVariables>,
|
|
119
|
-
options?:
|
|
119
|
+
options?: Readonly<{
|
|
120
120
|
fetchPolicy?: FetchQueryFetchPolicy,
|
|
121
121
|
networkCacheConfig?: CacheConfig,
|
|
122
122
|
}>,
|
|
@@ -139,7 +139,7 @@ function fetchQuery<TVariables: Variables, TData, TRawResponse>(
|
|
|
139
139
|
|
|
140
140
|
function readData(snapshot: Snapshot): TData {
|
|
141
141
|
handlePotentialSnapshotErrors(environment, snapshot.fieldErrors);
|
|
142
|
-
/* $FlowFixMe[incompatible-
|
|
142
|
+
/* $FlowFixMe[incompatible-type] we assume readData returns the right
|
|
143
143
|
* data just having written it from network or checked availability. */
|
|
144
144
|
return snapshot.data;
|
|
145
145
|
}
|
|
@@ -151,22 +151,35 @@ function fetchQuery<TVariables: Variables, TData, TRawResponse>(
|
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
153
|
case 'store-or-network': {
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
const queryAvailability = environment.check(operation);
|
|
155
|
+
const shouldFetch = queryAvailability.status !== 'available';
|
|
156
|
+
let observable;
|
|
157
|
+
if (!shouldFetch) {
|
|
158
|
+
observable = RelayObservable.from<Snapshot>(
|
|
156
159
|
environment.lookup(operation.fragment),
|
|
157
160
|
).map(readData);
|
|
161
|
+
} else {
|
|
162
|
+
observable = getNetworkObservable<$FlowFixMe>(
|
|
163
|
+
environment,
|
|
164
|
+
operation,
|
|
165
|
+
).map(readData);
|
|
158
166
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
167
|
+
environment.__log({
|
|
168
|
+
name: 'fetchquery.fetch',
|
|
169
|
+
operation,
|
|
170
|
+
fetchPolicy,
|
|
171
|
+
queryAvailability,
|
|
172
|
+
shouldFetch,
|
|
173
|
+
});
|
|
174
|
+
return observable;
|
|
162
175
|
}
|
|
163
176
|
default:
|
|
164
|
-
|
|
177
|
+
fetchPolicy as empty;
|
|
165
178
|
throw new Error('fetchQuery: Invalid fetchPolicy ' + fetchPolicy);
|
|
166
179
|
}
|
|
167
180
|
}
|
|
168
181
|
|
|
169
|
-
function getNetworkObservable<TQuery
|
|
182
|
+
function getNetworkObservable<TQuery extends OperationType>(
|
|
170
183
|
environment: IEnvironment,
|
|
171
184
|
operation: OperationDescriptor,
|
|
172
185
|
): RelayObservable<TQuery['response']> {
|
|
@@ -26,7 +26,7 @@ const {getRequest} = require('./GraphQLTag');
|
|
|
26
26
|
* order to be accessible in the result object.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
function fetchQuery_DEPRECATED<T
|
|
29
|
+
function fetchQuery_DEPRECATED<T extends OperationType>(
|
|
30
30
|
environment: IEnvironment,
|
|
31
31
|
taggedNode: GraphQLTaggedNode,
|
|
32
32
|
variables: T['variables'],
|
|
@@ -68,7 +68,7 @@ function check(
|
|
|
68
68
|
getTargetForActor: (actorIdentifier: ActorIdentifier) => MutableRecordSource,
|
|
69
69
|
defaultActorIdentifier: ActorIdentifier,
|
|
70
70
|
selector: NormalizationSelector,
|
|
71
|
-
handlers:
|
|
71
|
+
handlers: ReadonlyArray<MissingFieldHandler>,
|
|
72
72
|
operationLoader: ?OperationLoader,
|
|
73
73
|
getDataID: GetDataID,
|
|
74
74
|
shouldProcessClientComponents: ?boolean,
|
|
@@ -108,7 +108,7 @@ function check(
|
|
|
108
108
|
* @private
|
|
109
109
|
*/
|
|
110
110
|
class DataChecker {
|
|
111
|
-
_handlers:
|
|
111
|
+
_handlers: ReadonlyArray<MissingFieldHandler>;
|
|
112
112
|
_mostRecentlyInvalidatedAt: number | null;
|
|
113
113
|
_mutator: RelayRecordSourceMutator;
|
|
114
114
|
_operationLoader: OperationLoader | null;
|
|
@@ -136,7 +136,7 @@ class DataChecker {
|
|
|
136
136
|
) => MutableRecordSource,
|
|
137
137
|
defaultActorIdentifier: ActorIdentifier,
|
|
138
138
|
variables: Variables,
|
|
139
|
-
handlers:
|
|
139
|
+
handlers: ReadonlyArray<MissingFieldHandler>,
|
|
140
140
|
operationLoader: ?OperationLoader,
|
|
141
141
|
getDataID: GetDataID,
|
|
142
142
|
shouldProcessClientComponents: ?boolean,
|
|
@@ -193,16 +193,16 @@ class DataChecker {
|
|
|
193
193
|
|
|
194
194
|
return this._recordWasMissing === true
|
|
195
195
|
? {
|
|
196
|
-
status: 'missing',
|
|
197
196
|
mostRecentlyInvalidatedAt: this._mostRecentlyInvalidatedAt,
|
|
197
|
+
status: 'missing',
|
|
198
198
|
}
|
|
199
199
|
: {
|
|
200
|
-
status: 'available',
|
|
201
200
|
mostRecentlyInvalidatedAt: this._mostRecentlyInvalidatedAt,
|
|
201
|
+
status: 'available',
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
_getVariableValue(name: string):
|
|
205
|
+
_getVariableValue(name: string): unknown {
|
|
206
206
|
invariant(
|
|
207
207
|
this._variables.hasOwnProperty(name),
|
|
208
208
|
'RelayAsyncLoader(): Undefined variable `%s`.',
|
|
@@ -218,7 +218,7 @@ class DataChecker {
|
|
|
218
218
|
_handleMissingScalarField(
|
|
219
219
|
field: NormalizationScalarField,
|
|
220
220
|
dataID: DataID,
|
|
221
|
-
):
|
|
221
|
+
): unknown {
|
|
222
222
|
if (field.name === 'id' && field.alias == null && isClientID(dataID)) {
|
|
223
223
|
return undefined;
|
|
224
224
|
}
|
|
@@ -239,6 +239,15 @@ class DataChecker {
|
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
+
if (this._log != null) {
|
|
243
|
+
this._log({
|
|
244
|
+
name: 'store.datachecker.missing',
|
|
245
|
+
kind: 'scalar',
|
|
246
|
+
dataID,
|
|
247
|
+
fieldName: field.name,
|
|
248
|
+
storageKey: getStorageKey(field, this._variables),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
242
251
|
this._handleMissing();
|
|
243
252
|
}
|
|
244
253
|
|
|
@@ -266,6 +275,15 @@ class DataChecker {
|
|
|
266
275
|
}
|
|
267
276
|
}
|
|
268
277
|
}
|
|
278
|
+
if (this._log != null) {
|
|
279
|
+
this._log({
|
|
280
|
+
name: 'store.datachecker.missing',
|
|
281
|
+
kind: 'linked',
|
|
282
|
+
dataID,
|
|
283
|
+
fieldName: field.name,
|
|
284
|
+
storageKey: getStorageKey(field, this._variables),
|
|
285
|
+
});
|
|
286
|
+
}
|
|
269
287
|
this._handleMissing();
|
|
270
288
|
}
|
|
271
289
|
|
|
@@ -299,12 +317,28 @@ class DataChecker {
|
|
|
299
317
|
}
|
|
300
318
|
}
|
|
301
319
|
}
|
|
320
|
+
if (this._log != null) {
|
|
321
|
+
this._log({
|
|
322
|
+
name: 'store.datachecker.missing',
|
|
323
|
+
kind: 'pluralLinked',
|
|
324
|
+
dataID,
|
|
325
|
+
fieldName: field.name,
|
|
326
|
+
storageKey: getStorageKey(field, this._variables),
|
|
327
|
+
});
|
|
328
|
+
}
|
|
302
329
|
this._handleMissing();
|
|
303
330
|
}
|
|
304
331
|
|
|
305
332
|
_traverse(node: NormalizationNode, dataID: DataID): void {
|
|
306
333
|
const status = this._mutator.getStatus(dataID);
|
|
307
334
|
if (status === UNKNOWN) {
|
|
335
|
+
if (this._log != null) {
|
|
336
|
+
this._log({
|
|
337
|
+
name: 'store.datachecker.missing',
|
|
338
|
+
kind: 'unknown_record',
|
|
339
|
+
dataID,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
308
342
|
this._handleMissing();
|
|
309
343
|
}
|
|
310
344
|
|
|
@@ -323,7 +357,7 @@ class DataChecker {
|
|
|
323
357
|
}
|
|
324
358
|
|
|
325
359
|
_traverseSelections(
|
|
326
|
-
selections:
|
|
360
|
+
selections: ReadonlyArray<NormalizationSelection>,
|
|
327
361
|
dataID: DataID,
|
|
328
362
|
): void {
|
|
329
363
|
selections.forEach(selection => {
|
|
@@ -470,7 +504,7 @@ class DataChecker {
|
|
|
470
504
|
}
|
|
471
505
|
break;
|
|
472
506
|
default:
|
|
473
|
-
|
|
507
|
+
selection as empty;
|
|
474
508
|
invariant(
|
|
475
509
|
false,
|
|
476
510
|
'RelayAsyncLoader(): Unexpected ast kind `%s`.',
|