@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
package/core/QueryManager.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { DefaultOptions } from "./ApolloClient.js";
|
|
|
9
9
|
import type { LocalState } from "./LocalState.js";
|
|
10
10
|
import { NetworkStatus } from "./networkStatus.js";
|
|
11
11
|
import { ObservableQuery } from "./ObservableQuery.js";
|
|
12
|
-
import type { ApolloQueryResult, DefaultContext, InternalRefetchQueriesInclude, InternalRefetchQueriesMap, InternalRefetchQueriesOptions, MutationUpdaterFunction, OnQueryUpdated, OperationVariables } from "./types.js";
|
|
12
|
+
import type { ApolloQueryResult, DefaultContext, InternalRefetchQueriesInclude, InternalRefetchQueriesMap, InternalRefetchQueriesOptions, MutateResult, MutationUpdaterFunction, OnQueryUpdated, OperationVariables, SubscribeResult } from "./types.js";
|
|
13
13
|
import type { ErrorPolicy, MutationFetchPolicy, MutationOptions, QueryOptions, SubscriptionOptions, WatchQueryFetchPolicy, WatchQueryOptions } from "./watchQueryOptions.js";
|
|
14
14
|
interface MutationStoreValue {
|
|
15
15
|
mutation: DocumentNode;
|
|
@@ -65,6 +65,17 @@ export declare class QueryManager {
|
|
|
65
65
|
private queryDeduplication;
|
|
66
66
|
private clientAwareness;
|
|
67
67
|
private localState;
|
|
68
|
+
/**
|
|
69
|
+
* Whether to prioritize cache values over network results when
|
|
70
|
+
* `fetchObservableWithInfo` is called.
|
|
71
|
+
* This will essentially turn a `"network-only"` or `"cache-and-network"`
|
|
72
|
+
* fetchPolicy into a `"cache-first"` fetchPolicy, but without influencing
|
|
73
|
+
* the `fetchPolicy` of the `ObservableQuery`.
|
|
74
|
+
*
|
|
75
|
+
* This can e.g. be used to prioritize the cache during the first render after
|
|
76
|
+
* SSR.
|
|
77
|
+
*/
|
|
78
|
+
prioritizeCacheValues: boolean;
|
|
68
79
|
private onBroadcast?;
|
|
69
80
|
mutationStore?: {
|
|
70
81
|
[mutationId: string]: MutationStoreValue;
|
|
@@ -78,7 +89,7 @@ export declare class QueryManager {
|
|
|
78
89
|
*/
|
|
79
90
|
stop(): void;
|
|
80
91
|
private cancelPendingFetches;
|
|
81
|
-
mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<
|
|
92
|
+
mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<MutateResult<MaybeMasked<TData>>>;
|
|
82
93
|
markMutationResult<TData, TVariables extends OperationVariables, TContext, TCache extends ApolloCache>(mutation: {
|
|
83
94
|
mutationId: string;
|
|
84
95
|
result: FetchResult<TData>;
|
|
@@ -123,7 +134,7 @@ export declare class QueryManager {
|
|
|
123
134
|
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
|
|
124
135
|
reFetchObservableQueries(includeStandby?: boolean): Promise<ApolloQueryResult<any>[]>;
|
|
125
136
|
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
|
|
126
|
-
startGraphQLSubscription<TData = unknown>(options: SubscriptionOptions): Observable<
|
|
137
|
+
startGraphQLSubscription<TData = unknown>(options: SubscriptionOptions): Observable<SubscribeResult<TData>>;
|
|
127
138
|
stopQuery(queryId: string): void;
|
|
128
139
|
removeQuery(queryId: string): void;
|
|
129
140
|
broadcastQueries(): void;
|
package/core/QueryManager.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Trie } from "@wry/trie";
|
|
2
|
-
import { catchError, concat, EMPTY, from, lastValueFrom, map, mergeMap, mergeWith, Observable, of, share, shareReplay, Subject, tap, } from "rxjs";
|
|
2
|
+
import { catchError, concat, EMPTY, filter, from, lastValueFrom, map, mergeMap, mergeWith, Observable, of, share, shareReplay, Subject, tap, } from "rxjs";
|
|
3
3
|
import { canonicalStringify } from "@apollo/client/cache";
|
|
4
4
|
import { CombinedGraphQLErrors, graphQLResultHasProtocolErrors, UnconventionalError, } from "@apollo/client/errors";
|
|
5
5
|
import { PROTOCOL_ERRORS_SYMBOL } from "@apollo/client/errors";
|
|
@@ -30,6 +30,17 @@ export class QueryManager {
|
|
|
30
30
|
queryDeduplication;
|
|
31
31
|
clientAwareness = {};
|
|
32
32
|
localState;
|
|
33
|
+
/**
|
|
34
|
+
* Whether to prioritize cache values over network results when
|
|
35
|
+
* `fetchObservableWithInfo` is called.
|
|
36
|
+
* This will essentially turn a `"network-only"` or `"cache-and-network"`
|
|
37
|
+
* fetchPolicy into a `"cache-first"` fetchPolicy, but without influencing
|
|
38
|
+
* the `fetchPolicy` of the `ObservableQuery`.
|
|
39
|
+
*
|
|
40
|
+
* This can e.g. be used to prioritize the cache during the first render after
|
|
41
|
+
* SSR.
|
|
42
|
+
*/
|
|
43
|
+
prioritizeCacheValues = false;
|
|
33
44
|
onBroadcast;
|
|
34
45
|
mutationStore;
|
|
35
46
|
// All the queries that the QueryManager is currently managing (not
|
|
@@ -77,15 +88,15 @@ export class QueryManager {
|
|
|
77
88
|
this.queries.forEach((_info, queryId) => {
|
|
78
89
|
this.removeQuery(queryId);
|
|
79
90
|
});
|
|
80
|
-
this.cancelPendingFetches(newInvariantError(
|
|
91
|
+
this.cancelPendingFetches(newInvariantError(68));
|
|
81
92
|
}
|
|
82
93
|
cancelPendingFetches(error) {
|
|
83
94
|
this.fetchCancelFns.forEach((cancel) => cancel(error));
|
|
84
95
|
this.fetchCancelFns.clear();
|
|
85
96
|
}
|
|
86
97
|
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, }) {
|
|
87
|
-
invariant(mutation,
|
|
88
|
-
invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache",
|
|
98
|
+
invariant(mutation, 69);
|
|
99
|
+
invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 70);
|
|
89
100
|
const mutationId = this.generateMutationId();
|
|
90
101
|
mutation = this.cache.transformForLink(this.transform(mutation));
|
|
91
102
|
const { hasClientExports } = this.getDocumentInfo(mutation);
|
|
@@ -119,7 +130,8 @@ export class QueryManager {
|
|
|
119
130
|
optimisticResponse: isOptimistic ? optimisticResponse : void 0,
|
|
120
131
|
}, variables, {}, false)
|
|
121
132
|
.pipe(mergeMap((result) => {
|
|
122
|
-
|
|
133
|
+
const hasErrors = graphQLResultHasError(result);
|
|
134
|
+
if (hasErrors && errorPolicy === "none") {
|
|
123
135
|
throw new CombinedGraphQLErrors(getGraphQLErrorsFromResult(result));
|
|
124
136
|
}
|
|
125
137
|
if (mutationStoreValue) {
|
|
@@ -130,8 +142,7 @@ export class QueryManager {
|
|
|
130
142
|
if (typeof refetchQueries === "function") {
|
|
131
143
|
refetchQueries = refetchQueries(storeResult);
|
|
132
144
|
}
|
|
133
|
-
if (errorPolicy === "ignore" &&
|
|
134
|
-
graphQLResultHasError(storeResult)) {
|
|
145
|
+
if (errorPolicy === "ignore" && hasErrors) {
|
|
135
146
|
delete storeResult.errors;
|
|
136
147
|
}
|
|
137
148
|
return from(this.markMutationResult({
|
|
@@ -160,28 +171,40 @@ export class QueryManager {
|
|
|
160
171
|
// ExecutionPatchResult has arrived and we have assembled the
|
|
161
172
|
// multipart response into a single result.
|
|
162
173
|
if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
|
|
163
|
-
|
|
164
|
-
...storeResult,
|
|
174
|
+
const result = {
|
|
165
175
|
data: this.maskOperation({
|
|
166
176
|
document: mutation,
|
|
167
177
|
data: storeResult.data,
|
|
168
178
|
fetchPolicy,
|
|
169
179
|
id: mutationId,
|
|
170
180
|
}),
|
|
171
|
-
}
|
|
181
|
+
};
|
|
182
|
+
if (graphQLResultHasError(storeResult)) {
|
|
183
|
+
result.error = new CombinedGraphQLErrors(getGraphQLErrorsFromResult(storeResult));
|
|
184
|
+
}
|
|
185
|
+
if (storeResult.extensions) {
|
|
186
|
+
result.extensions = storeResult.extensions;
|
|
187
|
+
}
|
|
188
|
+
resolve(result);
|
|
172
189
|
}
|
|
173
190
|
},
|
|
174
191
|
error: (err) => {
|
|
175
|
-
|
|
192
|
+
const error = maybeWrapError(err);
|
|
176
193
|
if (mutationStoreValue) {
|
|
177
194
|
mutationStoreValue.loading = false;
|
|
178
|
-
mutationStoreValue.error =
|
|
195
|
+
mutationStoreValue.error = error;
|
|
179
196
|
}
|
|
180
197
|
if (isOptimistic) {
|
|
181
198
|
this.cache.removeOptimistic(mutationId);
|
|
182
199
|
}
|
|
183
200
|
this.broadcastQueries();
|
|
184
|
-
|
|
201
|
+
if (errorPolicy === "ignore") {
|
|
202
|
+
return resolve({ data: undefined });
|
|
203
|
+
}
|
|
204
|
+
if (errorPolicy === "all") {
|
|
205
|
+
return resolve({ data: undefined, error });
|
|
206
|
+
}
|
|
207
|
+
reject(error);
|
|
185
208
|
},
|
|
186
209
|
});
|
|
187
210
|
});
|
|
@@ -454,10 +477,10 @@ export class QueryManager {
|
|
|
454
477
|
// TODO: catch `EmptyError` and rethrow as network error if `complete`
|
|
455
478
|
// notification is emitted without a value.
|
|
456
479
|
query(options, queryId = this.generateQueryId()) {
|
|
457
|
-
invariant(options.query,
|
|
458
|
-
invariant(options.query.kind === "Document",
|
|
459
|
-
invariant(!options.returnPartialData,
|
|
460
|
-
invariant(!options.pollInterval,
|
|
480
|
+
invariant(options.query, 71);
|
|
481
|
+
invariant(options.query.kind === "Document", 72);
|
|
482
|
+
invariant(!options.returnPartialData, 73);
|
|
483
|
+
invariant(!options.pollInterval, 74);
|
|
461
484
|
const query = this.transform(options.query);
|
|
462
485
|
return this.fetchQuery(queryId, { ...options, query })
|
|
463
486
|
.then((result) => result && {
|
|
@@ -491,7 +514,7 @@ export class QueryManager {
|
|
|
491
514
|
// depend on values that previously existed in the data portion of the
|
|
492
515
|
// store. So, we cancel the promises and observers that we have issued
|
|
493
516
|
// so far and not yet resolved (in the case of queries).
|
|
494
|
-
this.cancelPendingFetches(newInvariantError(
|
|
517
|
+
this.cancelPendingFetches(newInvariantError(75));
|
|
495
518
|
this.queries.forEach((queryInfo) => {
|
|
496
519
|
if (queryInfo.observableQuery) {
|
|
497
520
|
// Set loading to true so listeners don't trigger unless they want
|
|
@@ -579,10 +602,10 @@ export class QueryManager {
|
|
|
579
602
|
if (!included) {
|
|
580
603
|
const queryName = queryNames.get(nameOrQueryString);
|
|
581
604
|
if (queryName) {
|
|
582
|
-
__DEV__ && invariant.warn(
|
|
605
|
+
__DEV__ && invariant.warn(76, queryName);
|
|
583
606
|
}
|
|
584
607
|
else {
|
|
585
|
-
__DEV__ && invariant.warn(
|
|
608
|
+
__DEV__ && invariant.warn(77);
|
|
586
609
|
}
|
|
587
610
|
}
|
|
588
611
|
});
|
|
@@ -611,38 +634,48 @@ export class QueryManager {
|
|
|
611
634
|
const { fetchPolicy, errorPolicy = "none", context = {}, extensions = {}, } = options;
|
|
612
635
|
query = this.transform(query);
|
|
613
636
|
variables = this.getVariables(query, variables);
|
|
614
|
-
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe(map((
|
|
637
|
+
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe(map((rawResult) => {
|
|
615
638
|
if (fetchPolicy !== "no-cache") {
|
|
616
639
|
// the subscription interface should handle not sending us results we no longer subscribe to.
|
|
617
640
|
// XXX I don't think we ever send in an object with errors, but we might in the future...
|
|
618
|
-
if (shouldWriteResult(
|
|
641
|
+
if (shouldWriteResult(rawResult, errorPolicy)) {
|
|
619
642
|
this.cache.write({
|
|
620
643
|
query,
|
|
621
|
-
result:
|
|
644
|
+
result: rawResult.data,
|
|
622
645
|
dataId: "ROOT_SUBSCRIPTION",
|
|
623
646
|
variables: variables,
|
|
624
647
|
});
|
|
625
648
|
}
|
|
626
649
|
this.broadcastQueries();
|
|
627
650
|
}
|
|
628
|
-
const
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
651
|
+
const result = {
|
|
652
|
+
data: rawResult.data ?? undefined,
|
|
653
|
+
};
|
|
654
|
+
if (graphQLResultHasError(rawResult)) {
|
|
655
|
+
result.error = new CombinedGraphQLErrors(rawResult.errors);
|
|
656
|
+
}
|
|
657
|
+
else if (graphQLResultHasProtocolErrors(rawResult)) {
|
|
658
|
+
result.error = rawResult.extensions[PROTOCOL_ERRORS_SYMBOL];
|
|
659
|
+
// Don't emit protocol errors added by HttpLink
|
|
660
|
+
delete rawResult.extensions[PROTOCOL_ERRORS_SYMBOL];
|
|
661
|
+
}
|
|
662
|
+
if (rawResult.extensions &&
|
|
663
|
+
Object.keys(rawResult.extensions).length) {
|
|
664
|
+
result.extensions = rawResult.extensions;
|
|
632
665
|
}
|
|
633
|
-
if (
|
|
634
|
-
|
|
635
|
-
// to our documentation, so we throw protocol errors regardless of the
|
|
636
|
-
// set error policy.
|
|
637
|
-
throw result.extensions[PROTOCOL_ERRORS_SYMBOL];
|
|
666
|
+
if (result.error && errorPolicy === "none") {
|
|
667
|
+
result.data = undefined;
|
|
638
668
|
}
|
|
639
669
|
if (errorPolicy === "ignore") {
|
|
640
|
-
delete result.
|
|
670
|
+
delete result.error;
|
|
641
671
|
}
|
|
642
672
|
return result;
|
|
643
673
|
}), catchError((error) => {
|
|
644
|
-
|
|
645
|
-
|
|
674
|
+
if (errorPolicy === "ignore") {
|
|
675
|
+
return of({ data: undefined });
|
|
676
|
+
}
|
|
677
|
+
return of({ data: undefined, error: maybeWrapError(error) });
|
|
678
|
+
}), filter((result) => !!(result.data || result.error)));
|
|
646
679
|
if (this.getDocumentInfo(query).hasClientExports) {
|
|
647
680
|
const observablePromise = this.localState
|
|
648
681
|
.addExportedVariables(query, variables, context)
|
|
@@ -810,6 +843,10 @@ export class QueryManager {
|
|
|
810
843
|
const queryInfo = this.getQuery(queryId);
|
|
811
844
|
const defaults = this.defaultOptions.watchQuery;
|
|
812
845
|
let { fetchPolicy = (defaults && defaults.fetchPolicy) || "cache-first", errorPolicy = (defaults && defaults.errorPolicy) || "none", returnPartialData = false, notifyOnNetworkStatusChange = false, context = {}, } = options;
|
|
846
|
+
if (this.prioritizeCacheValues &&
|
|
847
|
+
(fetchPolicy === "network-only" || fetchPolicy === "cache-and-network")) {
|
|
848
|
+
fetchPolicy = "cache-first";
|
|
849
|
+
}
|
|
813
850
|
const normalized = Object.assign({}, options, {
|
|
814
851
|
query,
|
|
815
852
|
variables,
|
|
@@ -1009,7 +1046,7 @@ export class QueryManager {
|
|
|
1009
1046
|
!isFullyUnmaskedOperation(document) &&
|
|
1010
1047
|
!this.noCacheWarningsByQueryId.has(operationId)) {
|
|
1011
1048
|
this.noCacheWarningsByQueryId.add(operationId);
|
|
1012
|
-
__DEV__ && invariant.warn(
|
|
1049
|
+
__DEV__ && invariant.warn(78, getOperationName(document) ??
|
|
1013
1050
|
`Unnamed ${operationType ?? "operation"}`);
|
|
1014
1051
|
}
|
|
1015
1052
|
}
|