@apollo/client 4.0.0-alpha.3 → 4.0.0-alpha.5
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/.changeset/eighty-squids-fix.md +15 -0
- package/.changeset/eleven-kangaroos-jump.md +5 -0
- package/.changeset/forty-shrimps-fry.md +5 -0
- package/.changeset/funny-jeans-invent.md +16 -0
- package/.changeset/grumpy-vans-type.md +5 -0
- package/.changeset/khaki-spies-work.md +11 -0
- package/.changeset/light-apes-rescue.md +5 -0
- package/.changeset/little-spoons-kick.md +7 -0
- package/.changeset/loud-cows-raise.md +7 -0
- package/.changeset/many-buses-allow.md +5 -0
- package/.changeset/odd-lemons-relax.md +5 -0
- package/.changeset/poor-eels-punch.md +5 -0
- package/.changeset/pre.json +18 -0
- package/.changeset/real-teachers-peel.md +5 -0
- package/.changeset/slimy-chicken-melt.md +5 -0
- package/.changeset/thick-books-grin.md +5 -0
- package/.changeset/tough-rockets-allow.md +5 -0
- package/.changeset/tricky-tables-shave.md +5 -0
- package/.changeset/warm-ties-sit.md +7 -0
- package/CHANGELOG.md +84 -0
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +4 -4
- package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/core/ApolloClient.cjs +25 -16
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +17 -5
- package/__cjs/core/LocalState.cjs +2 -2
- package/__cjs/core/ObservableQuery.cjs +44 -22
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +6 -3
- package/__cjs/core/QueryManager.cjs +72 -35
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +14 -3
- package/__cjs/core/types.d.cts +32 -0
- package/__cjs/core/watchQueryOptions.d.cts +18 -25
- package/__cjs/invariantErrorCodes.cjs +57 -77
- package/__cjs/link/core/ApolloLink.cjs +2 -2
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/createHttpLink.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
- package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
- package/__cjs/link/persisted-queries/index.cjs +2 -2
- package/__cjs/link/utils/validateOperation.cjs +1 -1
- package/__cjs/masking/maskDefinition.cjs +2 -2
- package/__cjs/masking/maskFragment.cjs +2 -2
- package/__cjs/masking/maskOperation.cjs +1 -1
- package/__cjs/masking/utils.cjs +1 -1
- package/__cjs/react/context/ApolloConsumer.cjs +1 -1
- package/__cjs/react/context/ApolloContext.cjs +1 -1
- package/__cjs/react/context/ApolloContext.cjs.map +1 -1
- package/__cjs/react/context/ApolloContext.d.cts +2 -2
- package/__cjs/react/context/ApolloProvider.cjs +1 -1
- package/__cjs/react/hooks/index.cjs +13 -8
- package/__cjs/react/hooks/index.cjs.map +1 -1
- package/__cjs/react/hooks/index.d.cts +6 -12
- package/__cjs/react/hooks/internal/wrapHook.cjs +26 -5
- package/__cjs/react/hooks/internal/wrapHook.cjs.map +1 -1
- package/__cjs/react/hooks/internal/wrapHook.d.cts +3 -1
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +146 -43
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +51 -26
- package/__cjs/react/hooks/useLazyQuery.cjs +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +263 -262
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +105 -32
- package/__cjs/react/hooks/useMutation.cjs +14 -19
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +198 -3
- package/__cjs/react/hooks/useQuery.cjs +82 -189
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +283 -4
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.d.cts +21 -20
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.d.cts +26 -24
- package/__cjs/react/hooks/useSubscription.cjs +8 -57
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +96 -9
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.d.cts +40 -37
- package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -2
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +202 -35
- package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
- package/__cjs/react/index.cjs.map +1 -1
- package/__cjs/react/index.d.cts +2 -1
- package/__cjs/react/internal/index.cjs +3 -1
- package/__cjs/react/internal/index.cjs.map +1 -1
- package/__cjs/react/internal/index.d.cts +2 -0
- package/__cjs/react/internal/types.d.cts +46 -0
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +2 -3
- package/__cjs/react/ssr/getDataFromTree.cjs +43 -12
- package/__cjs/react/ssr/getDataFromTree.cjs.map +1 -1
- package/__cjs/react/ssr/getDataFromTree.d.cts +5 -0
- package/__cjs/react/ssr/index.cjs +1 -3
- package/__cjs/react/ssr/index.cjs.map +1 -1
- package/__cjs/react/ssr/index.d.cts +0 -1
- package/__cjs/react/ssr/useSSRQuery.cjs +60 -0
- package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -0
- package/__cjs/react/ssr/useSSRQuery.d.cts +5 -0
- package/__cjs/react/types/deprecated.cjs +3 -0
- package/__cjs/react/types/deprecated.cjs.map +1 -0
- package/__cjs/react/types/deprecated.d.cts +65 -0
- package/__cjs/react/types/types.documentation.d.cts +4 -12
- package/__cjs/testing/matchers/index.cjs +4 -0
- package/__cjs/testing/matchers/index.cjs.map +1 -1
- package/__cjs/testing/matchers/toEmitStrictTyped.cjs +42 -0
- package/__cjs/testing/matchers/toEmitStrictTyped.cjs.map +1 -0
- package/__cjs/testing/matchers/toEmitStrictTyped.d.cts +7 -0
- package/__cjs/testing/matchers/toEqualLazyQueryResult.cjs.map +1 -1
- package/__cjs/testing/matchers/toEqualLazyQueryResult.d.cts +2 -2
- package/__cjs/testing/matchers/toEqualQueryResult.cjs.map +1 -1
- package/__cjs/testing/matchers/toEqualQueryResult.d.cts +2 -2
- package/__cjs/testing/matchers/toEqualStrictTyped.cjs +26 -0
- package/__cjs/testing/matchers/toEqualStrictTyped.cjs.map +1 -0
- package/__cjs/testing/matchers/toEqualStrictTyped.d.cts +3 -0
- package/__cjs/testing/matchers/utils/getSerializableProperties.cjs +23 -0
- package/__cjs/testing/matchers/utils/getSerializableProperties.cjs.map +1 -0
- package/__cjs/testing/matchers/utils/getSerializableProperties.d.cts +2 -0
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.d.cts +1 -1
- package/cache/core/cache.js +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +4 -4
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.d.ts +17 -5
- package/core/ApolloClient.js +25 -16
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -2
- package/core/ObservableQuery.d.ts +6 -3
- package/core/ObservableQuery.js +44 -22
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts +14 -3
- package/core/QueryManager.js +73 -36
- package/core/QueryManager.js.map +1 -1
- package/core/types.d.ts +32 -0
- package/core/watchQueryOptions.d.ts +18 -25
- package/invariantErrorCodes.js +57 -77
- package/link/core/ApolloLink.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/utils/validateOperation.js +1 -1
- package/masking/maskDefinition.js +2 -2
- package/masking/maskFragment.js +2 -2
- package/masking/maskOperation.js +1 -1
- package/masking/utils.js +1 -1
- package/package.json +1 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.d.ts +2 -2
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/hooks/index.d.ts +6 -12
- package/react/hooks/index.js +6 -6
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/internal/wrapHook.d.ts +3 -1
- package/react/hooks/internal/wrapHook.js +24 -5
- package/react/hooks/internal/wrapHook.js.map +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +146 -43
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.d.ts +51 -26
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +263 -262
- package/react/hooks/useLazyQuery.js +1 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +105 -32
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +198 -3
- package/react/hooks/useMutation.js +14 -19
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +283 -4
- package/react/hooks/useQuery.js +83 -190
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +21 -20
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +26 -24
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +96 -9
- package/react/hooks/useSubscription.js +7 -53
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseFragment.d.ts +40 -37
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +202 -35
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/index.d.ts +2 -1
- package/react/index.js.map +1 -1
- package/react/internal/index.d.ts +2 -0
- package/react/internal/index.js +2 -1
- package/react/internal/index.js.map +1 -1
- package/react/internal/types.d.ts +46 -0
- package/react/query-preloader/createQueryPreloader.d.ts +2 -3
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/ssr/getDataFromTree.d.ts +5 -0
- package/react/ssr/getDataFromTree.js +43 -12
- package/react/ssr/getDataFromTree.js.map +1 -1
- package/react/ssr/index.d.ts +0 -1
- package/react/ssr/index.js +0 -1
- package/react/ssr/index.js.map +1 -1
- package/react/ssr/useSSRQuery.d.ts +5 -0
- package/react/ssr/useSSRQuery.js +56 -0
- package/react/ssr/useSSRQuery.js.map +1 -0
- package/react/types/deprecated.d.ts +65 -0
- package/react/types/deprecated.js +2 -0
- package/react/types/deprecated.js.map +1 -0
- package/react/types/types.documentation.d.ts +4 -12
- package/testing/matchers/index.js +4 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toEmitStrictTyped.d.ts +7 -0
- package/testing/matchers/toEmitStrictTyped.js +38 -0
- package/testing/matchers/toEmitStrictTyped.js.map +1 -0
- package/testing/matchers/toEqualLazyQueryResult.d.ts +2 -2
- package/testing/matchers/toEqualLazyQueryResult.js.map +1 -1
- package/testing/matchers/toEqualQueryResult.d.ts +2 -2
- package/testing/matchers/toEqualQueryResult.js.map +1 -1
- package/testing/matchers/toEqualStrictTyped.d.ts +3 -0
- package/testing/matchers/toEqualStrictTyped.js +22 -0
- package/testing/matchers/toEqualStrictTyped.js.map +1 -0
- package/testing/matchers/utils/getSerializableProperties.d.ts +2 -0
- package/testing/matchers/utils/getSerializableProperties.js +20 -0
- package/testing/matchers/utils/getSerializableProperties.js.map +1 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/__cjs/react/ssr/RenderPromises.cjs +0 -104
- package/__cjs/react/ssr/RenderPromises.cjs.map +0 -1
- package/__cjs/react/ssr/RenderPromises.d.cts +0 -22
- package/__cjs/react/types/types.d.cts +0 -661
- package/react/ssr/RenderPromises.d.ts +0 -22
- package/react/ssr/RenderPromises.js +0 -100
- package/react/ssr/RenderPromises.js.map +0 -1
- package/react/types/types.d.ts +0 -661
- /package/__cjs/react/{types → internal}/types.cjs +0 -0
- /package/__cjs/react/{types → internal}/types.cjs.map +0 -0
- /package/react/{types → internal}/types.js +0 -0
- /package/react/{types → internal}/types.js.map +0 -0
|
@@ -3,7 +3,6 @@ import type { Observable } from "rxjs";
|
|
|
3
3
|
import type { MissingFieldError } from "@apollo/client/cache";
|
|
4
4
|
import type { MissingTree } from "@apollo/client/cache";
|
|
5
5
|
import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
|
|
6
|
-
import { NetworkStatus } from "./networkStatus.cjs";
|
|
7
6
|
import type { QueryInfo } from "./QueryInfo.cjs";
|
|
8
7
|
import type { QueryManager } from "./QueryManager.cjs";
|
|
9
8
|
import type { ApolloQueryResult, ErrorLike, OperationVariables, TypedDocumentNode } from "./types.cjs";
|
|
@@ -78,7 +77,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
78
77
|
* This function returns _another_ function that you can call to terminate the subscription.
|
|
79
78
|
*/
|
|
80
79
|
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
|
|
81
|
-
|
|
80
|
+
/** @internal */
|
|
82
81
|
silentSetOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): void;
|
|
83
82
|
/**
|
|
84
83
|
* Update the variables of this observable query, and fetch the new results
|
|
@@ -117,7 +116,11 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
117
116
|
private fetch;
|
|
118
117
|
private updatePolling;
|
|
119
118
|
private updateLastResult;
|
|
120
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Reevaluate the query, optionally against new options. New options will be
|
|
121
|
+
* merged with the current options when given.
|
|
122
|
+
*/
|
|
123
|
+
reobserve(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
|
|
121
124
|
private observe;
|
|
122
125
|
private reportResult;
|
|
123
126
|
private reportError;
|
|
@@ -37,6 +37,17 @@ class QueryManager {
|
|
|
37
37
|
queryDeduplication;
|
|
38
38
|
clientAwareness = {};
|
|
39
39
|
localState;
|
|
40
|
+
/**
|
|
41
|
+
* Whether to prioritize cache values over network results when
|
|
42
|
+
* `fetchObservableWithInfo` is called.
|
|
43
|
+
* This will essentially turn a `"network-only"` or `"cache-and-network"`
|
|
44
|
+
* fetchPolicy into a `"cache-first"` fetchPolicy, but without influencing
|
|
45
|
+
* the `fetchPolicy` of the `ObservableQuery`.
|
|
46
|
+
*
|
|
47
|
+
* This can e.g. be used to prioritize the cache during the first render after
|
|
48
|
+
* SSR.
|
|
49
|
+
*/
|
|
50
|
+
prioritizeCacheValues = false;
|
|
40
51
|
onBroadcast;
|
|
41
52
|
mutationStore;
|
|
42
53
|
// All the queries that the QueryManager is currently managing (not
|
|
@@ -84,15 +95,15 @@ class QueryManager {
|
|
|
84
95
|
this.queries.forEach((_info, queryId) => {
|
|
85
96
|
this.removeQuery(queryId);
|
|
86
97
|
});
|
|
87
|
-
this.cancelPendingFetches((0, invariant_1.newInvariantError)(
|
|
98
|
+
this.cancelPendingFetches((0, invariant_1.newInvariantError)(68));
|
|
88
99
|
}
|
|
89
100
|
cancelPendingFetches(error) {
|
|
90
101
|
this.fetchCancelFns.forEach((cancel) => cancel(error));
|
|
91
102
|
this.fetchCancelFns.clear();
|
|
92
103
|
}
|
|
93
104
|
async mutate({ mutation, variables, optimisticResponse, updateQueries, refetchQueries = [], awaitRefetchQueries = false, update: updateWithProxyFn, onQueryUpdated, fetchPolicy = this.defaultOptions.mutate?.fetchPolicy || "network-only", errorPolicy = this.defaultOptions.mutate?.errorPolicy || "none", keepRootFields, context, }) {
|
|
94
|
-
(0, invariant_1.invariant)(mutation,
|
|
95
|
-
(0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache",
|
|
105
|
+
(0, invariant_1.invariant)(mutation, 69);
|
|
106
|
+
(0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 70);
|
|
96
107
|
const mutationId = this.generateMutationId();
|
|
97
108
|
mutation = this.cache.transformForLink(this.transform(mutation));
|
|
98
109
|
const { hasClientExports } = this.getDocumentInfo(mutation);
|
|
@@ -126,7 +137,8 @@ class QueryManager {
|
|
|
126
137
|
optimisticResponse: isOptimistic ? optimisticResponse : void 0,
|
|
127
138
|
}, variables, {}, false)
|
|
128
139
|
.pipe((0, rxjs_1.mergeMap)((result) => {
|
|
129
|
-
|
|
140
|
+
const hasErrors = (0, utilities_4.graphQLResultHasError)(result);
|
|
141
|
+
if (hasErrors && errorPolicy === "none") {
|
|
130
142
|
throw new errors_1.CombinedGraphQLErrors((0, utilities_4.getGraphQLErrorsFromResult)(result));
|
|
131
143
|
}
|
|
132
144
|
if (mutationStoreValue) {
|
|
@@ -137,8 +149,7 @@ class QueryManager {
|
|
|
137
149
|
if (typeof refetchQueries === "function") {
|
|
138
150
|
refetchQueries = refetchQueries(storeResult);
|
|
139
151
|
}
|
|
140
|
-
if (errorPolicy === "ignore" &&
|
|
141
|
-
(0, utilities_4.graphQLResultHasError)(storeResult)) {
|
|
152
|
+
if (errorPolicy === "ignore" && hasErrors) {
|
|
142
153
|
delete storeResult.errors;
|
|
143
154
|
}
|
|
144
155
|
return (0, rxjs_1.from)(this.markMutationResult({
|
|
@@ -167,28 +178,40 @@ class QueryManager {
|
|
|
167
178
|
// ExecutionPatchResult has arrived and we have assembled the
|
|
168
179
|
// multipart response into a single result.
|
|
169
180
|
if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
|
|
170
|
-
|
|
171
|
-
...storeResult,
|
|
181
|
+
const result = {
|
|
172
182
|
data: this.maskOperation({
|
|
173
183
|
document: mutation,
|
|
174
184
|
data: storeResult.data,
|
|
175
185
|
fetchPolicy,
|
|
176
186
|
id: mutationId,
|
|
177
187
|
}),
|
|
178
|
-
}
|
|
188
|
+
};
|
|
189
|
+
if ((0, utilities_4.graphQLResultHasError)(storeResult)) {
|
|
190
|
+
result.error = new errors_1.CombinedGraphQLErrors((0, utilities_4.getGraphQLErrorsFromResult)(storeResult));
|
|
191
|
+
}
|
|
192
|
+
if (storeResult.extensions) {
|
|
193
|
+
result.extensions = storeResult.extensions;
|
|
194
|
+
}
|
|
195
|
+
resolve(result);
|
|
179
196
|
}
|
|
180
197
|
},
|
|
181
198
|
error: (err) => {
|
|
182
|
-
|
|
199
|
+
const error = maybeWrapError(err);
|
|
183
200
|
if (mutationStoreValue) {
|
|
184
201
|
mutationStoreValue.loading = false;
|
|
185
|
-
mutationStoreValue.error =
|
|
202
|
+
mutationStoreValue.error = error;
|
|
186
203
|
}
|
|
187
204
|
if (isOptimistic) {
|
|
188
205
|
this.cache.removeOptimistic(mutationId);
|
|
189
206
|
}
|
|
190
207
|
this.broadcastQueries();
|
|
191
|
-
|
|
208
|
+
if (errorPolicy === "ignore") {
|
|
209
|
+
return resolve({ data: undefined });
|
|
210
|
+
}
|
|
211
|
+
if (errorPolicy === "all") {
|
|
212
|
+
return resolve({ data: undefined, error });
|
|
213
|
+
}
|
|
214
|
+
reject(error);
|
|
192
215
|
},
|
|
193
216
|
});
|
|
194
217
|
});
|
|
@@ -461,10 +484,10 @@ class QueryManager {
|
|
|
461
484
|
// TODO: catch `EmptyError` and rethrow as network error if `complete`
|
|
462
485
|
// notification is emitted without a value.
|
|
463
486
|
query(options, queryId = this.generateQueryId()) {
|
|
464
|
-
(0, invariant_1.invariant)(options.query,
|
|
465
|
-
(0, invariant_1.invariant)(options.query.kind === "Document",
|
|
466
|
-
(0, invariant_1.invariant)(!options.returnPartialData,
|
|
467
|
-
(0, invariant_1.invariant)(!options.pollInterval,
|
|
487
|
+
(0, invariant_1.invariant)(options.query, 71);
|
|
488
|
+
(0, invariant_1.invariant)(options.query.kind === "Document", 72);
|
|
489
|
+
(0, invariant_1.invariant)(!options.returnPartialData, 73);
|
|
490
|
+
(0, invariant_1.invariant)(!options.pollInterval, 74);
|
|
468
491
|
const query = this.transform(options.query);
|
|
469
492
|
return this.fetchQuery(queryId, { ...options, query })
|
|
470
493
|
.then((result) => result && {
|
|
@@ -498,7 +521,7 @@ class QueryManager {
|
|
|
498
521
|
// depend on values that previously existed in the data portion of the
|
|
499
522
|
// store. So, we cancel the promises and observers that we have issued
|
|
500
523
|
// so far and not yet resolved (in the case of queries).
|
|
501
|
-
this.cancelPendingFetches((0, invariant_1.newInvariantError)(
|
|
524
|
+
this.cancelPendingFetches((0, invariant_1.newInvariantError)(75));
|
|
502
525
|
this.queries.forEach((queryInfo) => {
|
|
503
526
|
if (queryInfo.observableQuery) {
|
|
504
527
|
// Set loading to true so listeners don't trigger unless they want
|
|
@@ -586,10 +609,10 @@ class QueryManager {
|
|
|
586
609
|
if (!included) {
|
|
587
610
|
const queryName = queryNames.get(nameOrQueryString);
|
|
588
611
|
if (queryName) {
|
|
589
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
612
|
+
__DEV__ && invariant_1.invariant.warn(76, queryName);
|
|
590
613
|
}
|
|
591
614
|
else {
|
|
592
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
615
|
+
__DEV__ && invariant_1.invariant.warn(77);
|
|
593
616
|
}
|
|
594
617
|
}
|
|
595
618
|
});
|
|
@@ -618,38 +641,48 @@ class QueryManager {
|
|
|
618
641
|
const { fetchPolicy, errorPolicy = "none", context = {}, extensions = {}, } = options;
|
|
619
642
|
query = this.transform(query);
|
|
620
643
|
variables = this.getVariables(query, variables);
|
|
621
|
-
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((
|
|
644
|
+
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((rawResult) => {
|
|
622
645
|
if (fetchPolicy !== "no-cache") {
|
|
623
646
|
// the subscription interface should handle not sending us results we no longer subscribe to.
|
|
624
647
|
// XXX I don't think we ever send in an object with errors, but we might in the future...
|
|
625
|
-
if ((0, QueryInfo_js_1.shouldWriteResult)(
|
|
648
|
+
if ((0, QueryInfo_js_1.shouldWriteResult)(rawResult, errorPolicy)) {
|
|
626
649
|
this.cache.write({
|
|
627
650
|
query,
|
|
628
|
-
result:
|
|
651
|
+
result: rawResult.data,
|
|
629
652
|
dataId: "ROOT_SUBSCRIPTION",
|
|
630
653
|
variables: variables,
|
|
631
654
|
});
|
|
632
655
|
}
|
|
633
656
|
this.broadcastQueries();
|
|
634
657
|
}
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
658
|
+
const result = {
|
|
659
|
+
data: rawResult.data ?? undefined,
|
|
660
|
+
};
|
|
661
|
+
if ((0, utilities_4.graphQLResultHasError)(rawResult)) {
|
|
662
|
+
result.error = new errors_1.CombinedGraphQLErrors(rawResult.errors);
|
|
663
|
+
}
|
|
664
|
+
else if ((0, errors_1.graphQLResultHasProtocolErrors)(rawResult)) {
|
|
665
|
+
result.error = rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
|
|
666
|
+
// Don't emit protocol errors added by HttpLink
|
|
667
|
+
delete rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
|
|
668
|
+
}
|
|
669
|
+
if (rawResult.extensions &&
|
|
670
|
+
Object.keys(rawResult.extensions).length) {
|
|
671
|
+
result.extensions = rawResult.extensions;
|
|
639
672
|
}
|
|
640
|
-
if (
|
|
641
|
-
|
|
642
|
-
// to our documentation, so we throw protocol errors regardless of the
|
|
643
|
-
// set error policy.
|
|
644
|
-
throw result.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
|
|
673
|
+
if (result.error && errorPolicy === "none") {
|
|
674
|
+
result.data = undefined;
|
|
645
675
|
}
|
|
646
676
|
if (errorPolicy === "ignore") {
|
|
647
|
-
delete result.
|
|
677
|
+
delete result.error;
|
|
648
678
|
}
|
|
649
679
|
return result;
|
|
650
680
|
}), (0, rxjs_1.catchError)((error) => {
|
|
651
|
-
|
|
652
|
-
|
|
681
|
+
if (errorPolicy === "ignore") {
|
|
682
|
+
return (0, rxjs_1.of)({ data: undefined });
|
|
683
|
+
}
|
|
684
|
+
return (0, rxjs_1.of)({ data: undefined, error: maybeWrapError(error) });
|
|
685
|
+
}), (0, rxjs_1.filter)((result) => !!(result.data || result.error)));
|
|
653
686
|
if (this.getDocumentInfo(query).hasClientExports) {
|
|
654
687
|
const observablePromise = this.localState
|
|
655
688
|
.addExportedVariables(query, variables, context)
|
|
@@ -817,6 +850,10 @@ class QueryManager {
|
|
|
817
850
|
const queryInfo = this.getQuery(queryId);
|
|
818
851
|
const defaults = this.defaultOptions.watchQuery;
|
|
819
852
|
let { fetchPolicy = (defaults && defaults.fetchPolicy) || "cache-first", errorPolicy = (defaults && defaults.errorPolicy) || "none", returnPartialData = false, notifyOnNetworkStatusChange = false, context = {}, } = options;
|
|
853
|
+
if (this.prioritizeCacheValues &&
|
|
854
|
+
(fetchPolicy === "network-only" || fetchPolicy === "cache-and-network")) {
|
|
855
|
+
fetchPolicy = "cache-first";
|
|
856
|
+
}
|
|
820
857
|
const normalized = Object.assign({}, options, {
|
|
821
858
|
query,
|
|
822
859
|
variables,
|
|
@@ -1016,7 +1053,7 @@ class QueryManager {
|
|
|
1016
1053
|
!(0, utilities_3.isFullyUnmaskedOperation)(document) &&
|
|
1017
1054
|
!this.noCacheWarningsByQueryId.has(operationId)) {
|
|
1018
1055
|
this.noCacheWarningsByQueryId.add(operationId);
|
|
1019
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
1056
|
+
__DEV__ && invariant_1.invariant.warn(78, (0, utilities_4.getOperationName)(document) ??
|
|
1020
1057
|
`Unnamed ${operationType ?? "operation"}`);
|
|
1021
1058
|
}
|
|
1022
1059
|
}
|