@apollo/client 4.0.0-alpha.4 → 4.0.0-alpha.6
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/eleven-kangaroos-jump.md +5 -0
- package/.changeset/forty-shrimps-fry.md +5 -0
- package/.changeset/giant-bags-share.md +5 -0
- package/.changeset/grumpy-vans-type.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/nervous-fireants-bow.md +5 -0
- package/.changeset/poor-eels-punch.md +5 -0
- package/.changeset/pre.json +17 -0
- package/.changeset/real-teachers-peel.md +5 -0
- package/.changeset/slimy-chicken-melt.md +5 -0
- package/.changeset/tame-points-work.md +11 -0
- package/.changeset/tender-swans-flash.md +16 -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 +72 -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/config/jest/areCombinedGraphQLErrorsEqual.cjs +3 -1
- package/__cjs/config/jest/areCombinedGraphQLErrorsEqual.cjs.map +1 -1
- package/__cjs/config/jest/setup.cjs +6 -0
- package/__cjs/config/jest/setup.cjs.map +1 -1
- package/__cjs/core/ApolloClient.cjs +9 -3
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +8 -8
- package/__cjs/core/LocalState.cjs +2 -2
- package/__cjs/core/ObservableQuery.cjs +25 -17
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +6 -6
- package/__cjs/core/QueryManager.cjs +78 -47
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +6 -6
- package/__cjs/core/types.d.cts +56 -2
- package/__cjs/errors/CombinedGraphQLErrors.cjs +8 -1
- package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedGraphQLErrors.d.cts +7 -2
- package/__cjs/invariantErrorCodes.cjs +108 -106
- 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/subscriptions/index.cjs +3 -1
- package/__cjs/link/subscriptions/index.cjs.map +1 -1
- 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/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/useApolloClient.cjs +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +4 -4
- package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
- package/__cjs/react/hooks/useMutation.cjs +14 -19
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +4 -4
- package/__cjs/react/hooks/useQuery.cjs +82 -187
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +7 -3
- package/__cjs/react/hooks/useSubscription.cjs +8 -57
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +6 -42
- package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -2
- package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
- package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +3 -3
- package/__cjs/react/internal/index.cjs +3 -1
- package/__cjs/react/internal/index.cjs.map +1 -1
- package/__cjs/react/internal/index.d.cts +1 -0
- package/__cjs/react/internal/types.d.cts +2 -2
- package/__cjs/react/parser/index.cjs +5 -5
- package/__cjs/react/ssr/getDataFromTree.cjs +24 -30
- package/__cjs/react/ssr/getDataFromTree.cjs.map +1 -1
- package/__cjs/react/ssr/getDataFromTree.d.cts +12 -1
- package/__cjs/react/ssr/index.cjs +3 -3
- package/__cjs/react/ssr/index.cjs.map +1 -1
- package/__cjs/react/ssr/index.d.cts +1 -1
- package/__cjs/react/ssr/prerenderStatic.cjs +151 -0
- package/__cjs/react/ssr/prerenderStatic.cjs.map +1 -0
- package/__cjs/react/ssr/prerenderStatic.d.cts +122 -0
- package/__cjs/react/ssr/renderToStringWithData.cjs +11 -5
- package/__cjs/react/ssr/renderToStringWithData.cjs.map +1 -1
- package/__cjs/react/ssr/renderToStringWithData.d.cts +5 -0
- 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.d.cts +1 -1
- package/__cjs/react/types/types.documentation.d.cts +4 -12
- package/__cjs/testing/internal/index.cjs +3 -1
- package/__cjs/testing/internal/index.cjs.map +1 -1
- package/__cjs/testing/internal/index.d.cts +1 -0
- package/__cjs/testing/internal/resetApolloContext.cjs +24 -0
- package/__cjs/testing/internal/resetApolloContext.cjs.map +1 -0
- package/__cjs/testing/internal/resetApolloContext.d.cts +10 -0
- package/__cjs/testing/matchers/index.cjs +2 -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/toEqualStrictTyped.cjs +2 -20
- package/__cjs/testing/matchers/toEqualStrictTyped.cjs.map +1 -1
- 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/utilities/internal/index.cjs +3 -1
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +1 -0
- package/__cjs/utilities/internal/toQueryResult.cjs +13 -0
- package/__cjs/utilities/internal/toQueryResult.cjs.map +1 -0
- package/__cjs/utilities/internal/toQueryResult.d.cts +3 -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/config/jest/areCombinedGraphQLErrorsEqual.js +3 -1
- package/config/jest/areCombinedGraphQLErrorsEqual.js.map +1 -1
- package/config/jest/setup.js +6 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ApolloClient.d.ts +8 -8
- package/core/ApolloClient.js +9 -3
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -2
- package/core/ObservableQuery.d.ts +6 -6
- package/core/ObservableQuery.js +25 -17
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts +6 -6
- package/core/QueryManager.js +80 -49
- package/core/QueryManager.js.map +1 -1
- package/core/types.d.ts +56 -2
- package/errors/CombinedGraphQLErrors.d.ts +7 -2
- package/errors/CombinedGraphQLErrors.js +8 -1
- package/errors/CombinedGraphQLErrors.js.map +1 -1
- package/invariantErrorCodes.js +108 -106
- 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/subscriptions/index.js +3 -1
- package/link/subscriptions/index.js.map +1 -1
- 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/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/useApolloClient.js +1 -1
- package/react/hooks/useLazyQuery.d.ts +4 -4
- package/react/hooks/useLazyQuery.js +2 -2
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.js +2 -2
- package/react/hooks/useMutation.d.ts +4 -4
- package/react/hooks/useMutation.js +14 -19
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +7 -3
- package/react/hooks/useQuery.js +83 -188
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +6 -42
- package/react/hooks/useSubscription.js +7 -53
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.d.ts +3 -3
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/index.d.ts +1 -0
- package/react/internal/index.js +2 -1
- package/react/internal/index.js.map +1 -1
- package/react/internal/types.d.ts +2 -2
- package/react/parser/index.js +5 -5
- package/react/ssr/getDataFromTree.d.ts +12 -1
- package/react/ssr/getDataFromTree.js +24 -29
- package/react/ssr/getDataFromTree.js.map +1 -1
- package/react/ssr/index.d.ts +1 -1
- package/react/ssr/index.js +1 -1
- package/react/ssr/index.js.map +1 -1
- package/react/ssr/prerenderStatic.d.ts +122 -0
- package/react/ssr/prerenderStatic.js +147 -0
- package/react/ssr/prerenderStatic.js.map +1 -0
- package/react/ssr/renderToStringWithData.d.ts +5 -0
- package/react/ssr/renderToStringWithData.js +11 -5
- package/react/ssr/renderToStringWithData.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 +1 -1
- package/react/types/types.documentation.d.ts +4 -12
- package/testing/internal/index.d.ts +1 -0
- package/testing/internal/index.js +2 -1
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/resetApolloContext.d.ts +10 -0
- package/testing/internal/resetApolloContext.js +20 -0
- package/testing/internal/resetApolloContext.js.map +1 -0
- package/testing/matchers/index.js +2 -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/toEqualStrictTyped.js +1 -19
- package/testing/matchers/toEqualStrictTyped.js.map +1 -1
- 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/utilities/internal/index.d.ts +1 -0
- package/utilities/internal/index.js +2 -1
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/toQueryResult.d.ts +3 -0
- package/utilities/internal/toQueryResult.js +10 -0
- package/utilities/internal/toQueryResult.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 -25
- package/__cjs/utilities/types/TODO.cjs +0 -3
- package/__cjs/utilities/types/TODO.cjs.map +0 -1
- package/__cjs/utilities/types/TODO.d.cts +0 -3
- package/react/ssr/RenderPromises.d.ts +0 -25
- package/react/ssr/RenderPromises.js +0 -100
- package/react/ssr/RenderPromises.js.map +0 -1
- package/utilities/types/TODO.d.ts +0 -3
- package/utilities/types/TODO.js +0 -2
- package/utilities/types/TODO.js.map +0 -1
|
@@ -5,7 +5,7 @@ import type { MissingTree } from "@apollo/client/cache";
|
|
|
5
5
|
import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
|
|
6
6
|
import type { QueryInfo } from "./QueryInfo.cjs";
|
|
7
7
|
import type { QueryManager } from "./QueryManager.cjs";
|
|
8
|
-
import type { ApolloQueryResult, ErrorLike, OperationVariables, TypedDocumentNode } from "./types.cjs";
|
|
8
|
+
import type { ApolloQueryResult, ErrorLike, OperationVariables, QueryResult, TypedDocumentNode } from "./types.cjs";
|
|
9
9
|
import type { FetchMoreQueryOptions, SubscribeToMoreOptions, UpdateQueryMapFn, WatchQueryOptions } from "./watchQueryOptions.cjs";
|
|
10
10
|
export interface FetchMoreOptions<TData = unknown, TVariables = OperationVariables> {
|
|
11
11
|
updateQuery?: (previousQueryResult: TData, options: {
|
|
@@ -61,7 +61,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
61
61
|
* @param variables - The new set of variables. If there are missing variables,
|
|
62
62
|
* the previous values of those variables will be used.
|
|
63
63
|
*/
|
|
64
|
-
refetch(variables?: Partial<TVariables>): Promise<
|
|
64
|
+
refetch(variables?: Partial<TVariables>): Promise<QueryResult<TData>>;
|
|
65
65
|
/**
|
|
66
66
|
* A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
|
|
67
67
|
*/
|
|
@@ -70,7 +70,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
70
70
|
fetchMoreResult: Unmasked<TFetchData>;
|
|
71
71
|
variables: TFetchVars;
|
|
72
72
|
}) => Unmasked<TData>;
|
|
73
|
-
}): Promise<
|
|
73
|
+
}): Promise<QueryResult<TFetchData>>;
|
|
74
74
|
/**
|
|
75
75
|
* A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
|
|
76
76
|
*
|
|
@@ -97,7 +97,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
97
97
|
* @param variables - The new set of variables. If there are missing variables,
|
|
98
98
|
* the previous values of those variables will be used.
|
|
99
99
|
*/
|
|
100
|
-
setVariables(variables: TVariables): Promise<
|
|
100
|
+
setVariables(variables: TVariables): Promise<QueryResult<TData>>;
|
|
101
101
|
/**
|
|
102
102
|
* A function that enables you to update the query's cached result without executing a followup GraphQL operation.
|
|
103
103
|
*
|
|
@@ -120,7 +120,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
120
120
|
* Reevaluate the query, optionally against new options. New options will be
|
|
121
121
|
* merged with the current options when given.
|
|
122
122
|
*/
|
|
123
|
-
reobserve(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>): Promise<
|
|
123
|
+
reobserve(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>): Promise<QueryResult<MaybeMasked<TData>>>;
|
|
124
124
|
private observe;
|
|
125
125
|
private reportResult;
|
|
126
126
|
private reportError;
|
|
@@ -129,6 +129,6 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
129
129
|
private transformDocument;
|
|
130
130
|
private maskResult;
|
|
131
131
|
}
|
|
132
|
-
export declare function reobserveCacheFirst<TData, TVars extends OperationVariables>(obsQuery: ObservableQuery<TData, TVars>): Promise<
|
|
132
|
+
export declare function reobserveCacheFirst<TData, TVars extends OperationVariables>(obsQuery: ObservableQuery<TData, TVars>): Promise<QueryResult<TData>>;
|
|
133
133
|
export declare function logMissingFieldErrors(missing: MissingFieldError | MissingTree | undefined): void;
|
|
134
134
|
//# sourceMappingURL=ObservableQuery.d.cts.map
|
|
@@ -95,15 +95,15 @@ class QueryManager {
|
|
|
95
95
|
this.queries.forEach((_info, queryId) => {
|
|
96
96
|
this.removeQuery(queryId);
|
|
97
97
|
});
|
|
98
|
-
this.cancelPendingFetches((0, invariant_1.newInvariantError)(
|
|
98
|
+
this.cancelPendingFetches((0, invariant_1.newInvariantError)(74));
|
|
99
99
|
}
|
|
100
100
|
cancelPendingFetches(error) {
|
|
101
101
|
this.fetchCancelFns.forEach((cancel) => cancel(error));
|
|
102
102
|
this.fetchCancelFns.clear();
|
|
103
103
|
}
|
|
104
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, }) {
|
|
105
|
-
(0, invariant_1.invariant)(mutation,
|
|
106
|
-
(0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache",
|
|
105
|
+
(0, invariant_1.invariant)(mutation, 75);
|
|
106
|
+
(0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 76);
|
|
107
107
|
const mutationId = this.generateMutationId();
|
|
108
108
|
mutation = this.cache.transformForLink(this.transform(mutation));
|
|
109
109
|
const { hasClientExports } = this.getDocumentInfo(mutation);
|
|
@@ -136,9 +136,10 @@ class QueryManager {
|
|
|
136
136
|
...context,
|
|
137
137
|
optimisticResponse: isOptimistic ? optimisticResponse : void 0,
|
|
138
138
|
}, variables, {}, false)
|
|
139
|
-
.pipe((0, rxjs_1.mergeMap)((result) => {
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
.pipe(validateDidEmitValue(), (0, rxjs_1.mergeMap)((result) => {
|
|
140
|
+
const hasErrors = (0, utilities_4.graphQLResultHasError)(result);
|
|
141
|
+
if (hasErrors && errorPolicy === "none") {
|
|
142
|
+
throw new errors_1.CombinedGraphQLErrors(result);
|
|
142
143
|
}
|
|
143
144
|
if (mutationStoreValue) {
|
|
144
145
|
mutationStoreValue.loading = false;
|
|
@@ -148,8 +149,7 @@ class QueryManager {
|
|
|
148
149
|
if (typeof refetchQueries === "function") {
|
|
149
150
|
refetchQueries = refetchQueries(storeResult);
|
|
150
151
|
}
|
|
151
|
-
if (errorPolicy === "ignore" &&
|
|
152
|
-
(0, utilities_4.graphQLResultHasError)(storeResult)) {
|
|
152
|
+
if (errorPolicy === "ignore" && hasErrors) {
|
|
153
153
|
delete storeResult.errors;
|
|
154
154
|
}
|
|
155
155
|
return (0, rxjs_1.from)(this.markMutationResult({
|
|
@@ -178,28 +178,40 @@ class QueryManager {
|
|
|
178
178
|
// ExecutionPatchResult has arrived and we have assembled the
|
|
179
179
|
// multipart response into a single result.
|
|
180
180
|
if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
|
|
181
|
-
|
|
182
|
-
...storeResult,
|
|
181
|
+
const result = {
|
|
183
182
|
data: this.maskOperation({
|
|
184
183
|
document: mutation,
|
|
185
184
|
data: storeResult.data,
|
|
186
185
|
fetchPolicy,
|
|
187
186
|
id: mutationId,
|
|
188
187
|
}),
|
|
189
|
-
}
|
|
188
|
+
};
|
|
189
|
+
if ((0, utilities_4.graphQLResultHasError)(storeResult)) {
|
|
190
|
+
result.error = new errors_1.CombinedGraphQLErrors(storeResult);
|
|
191
|
+
}
|
|
192
|
+
if (storeResult.extensions) {
|
|
193
|
+
result.extensions = storeResult.extensions;
|
|
194
|
+
}
|
|
195
|
+
resolve(result);
|
|
190
196
|
}
|
|
191
197
|
},
|
|
192
198
|
error: (err) => {
|
|
193
|
-
|
|
199
|
+
const error = maybeWrapError(err);
|
|
194
200
|
if (mutationStoreValue) {
|
|
195
201
|
mutationStoreValue.loading = false;
|
|
196
|
-
mutationStoreValue.error =
|
|
202
|
+
mutationStoreValue.error = error;
|
|
197
203
|
}
|
|
198
204
|
if (isOptimistic) {
|
|
199
205
|
this.cache.removeOptimistic(mutationId);
|
|
200
206
|
}
|
|
201
207
|
this.broadcastQueries();
|
|
202
|
-
|
|
208
|
+
if (errorPolicy === "ignore") {
|
|
209
|
+
return resolve({ data: undefined });
|
|
210
|
+
}
|
|
211
|
+
if (errorPolicy === "all") {
|
|
212
|
+
return resolve({ data: undefined, error });
|
|
213
|
+
}
|
|
214
|
+
reject(error);
|
|
203
215
|
},
|
|
204
216
|
});
|
|
205
217
|
});
|
|
@@ -389,7 +401,11 @@ class QueryManager {
|
|
|
389
401
|
return true;
|
|
390
402
|
}
|
|
391
403
|
fetchQuery(queryId, options, networkStatus) {
|
|
392
|
-
return (0, rxjs_1.lastValueFrom)(this.fetchObservableWithInfo(queryId, options, networkStatus).observable, {
|
|
404
|
+
return (0, rxjs_1.lastValueFrom)(this.fetchObservableWithInfo(queryId, options, networkStatus).observable.pipe((0, rxjs_1.map)(internal_1.toQueryResult)), {
|
|
405
|
+
// This default is needed when a `standby` fetch policy is used to avoid
|
|
406
|
+
// an EmptyError from rejecting this promise.
|
|
407
|
+
defaultValue: { data: undefined },
|
|
408
|
+
});
|
|
393
409
|
}
|
|
394
410
|
transform(document) {
|
|
395
411
|
return this.documentTransform.transformDocument(document);
|
|
@@ -469,24 +485,18 @@ class QueryManager {
|
|
|
469
485
|
});
|
|
470
486
|
return observable;
|
|
471
487
|
}
|
|
472
|
-
// TODO: catch `EmptyError` and rethrow as network error if `complete`
|
|
473
|
-
// notification is emitted without a value.
|
|
474
488
|
query(options, queryId = this.generateQueryId()) {
|
|
475
|
-
(0, invariant_1.invariant)(options.query, 75);
|
|
476
|
-
(0, invariant_1.invariant)(options.query.kind === "Document", 76);
|
|
477
|
-
(0, invariant_1.invariant)(!options.returnPartialData, 77);
|
|
478
|
-
(0, invariant_1.invariant)(!options.pollInterval, 78);
|
|
479
489
|
const query = this.transform(options.query);
|
|
480
490
|
return this.fetchQuery(queryId, { ...options, query })
|
|
481
|
-
.then((
|
|
482
|
-
...
|
|
491
|
+
.then((value) => ({
|
|
492
|
+
...value,
|
|
483
493
|
data: this.maskOperation({
|
|
484
494
|
document: query,
|
|
485
|
-
data:
|
|
495
|
+
data: value?.data,
|
|
486
496
|
fetchPolicy: options.fetchPolicy,
|
|
487
497
|
id: queryId,
|
|
488
498
|
}),
|
|
489
|
-
})
|
|
499
|
+
}))
|
|
490
500
|
.finally(() => this.stopQuery(queryId));
|
|
491
501
|
}
|
|
492
502
|
queryIdCounter = 1;
|
|
@@ -509,7 +519,7 @@ class QueryManager {
|
|
|
509
519
|
// depend on values that previously existed in the data portion of the
|
|
510
520
|
// store. So, we cancel the promises and observers that we have issued
|
|
511
521
|
// so far and not yet resolved (in the case of queries).
|
|
512
|
-
this.cancelPendingFetches((0, invariant_1.newInvariantError)(
|
|
522
|
+
this.cancelPendingFetches((0, invariant_1.newInvariantError)(77));
|
|
513
523
|
this.queries.forEach((queryInfo) => {
|
|
514
524
|
if (queryInfo.observableQuery) {
|
|
515
525
|
// Set loading to true so listeners don't trigger unless they want
|
|
@@ -597,10 +607,10 @@ class QueryManager {
|
|
|
597
607
|
if (!included) {
|
|
598
608
|
const queryName = queryNames.get(nameOrQueryString);
|
|
599
609
|
if (queryName) {
|
|
600
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
610
|
+
__DEV__ && invariant_1.invariant.warn(78, queryName);
|
|
601
611
|
}
|
|
602
612
|
else {
|
|
603
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
613
|
+
__DEV__ && invariant_1.invariant.warn(79);
|
|
604
614
|
}
|
|
605
615
|
}
|
|
606
616
|
});
|
|
@@ -629,38 +639,48 @@ class QueryManager {
|
|
|
629
639
|
const { fetchPolicy, errorPolicy = "none", context = {}, extensions = {}, } = options;
|
|
630
640
|
query = this.transform(query);
|
|
631
641
|
variables = this.getVariables(query, variables);
|
|
632
|
-
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((
|
|
642
|
+
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((rawResult) => {
|
|
633
643
|
if (fetchPolicy !== "no-cache") {
|
|
634
644
|
// the subscription interface should handle not sending us results we no longer subscribe to.
|
|
635
645
|
// XXX I don't think we ever send in an object with errors, but we might in the future...
|
|
636
|
-
if ((0, QueryInfo_js_1.shouldWriteResult)(
|
|
646
|
+
if ((0, QueryInfo_js_1.shouldWriteResult)(rawResult, errorPolicy)) {
|
|
637
647
|
this.cache.write({
|
|
638
648
|
query,
|
|
639
|
-
result:
|
|
649
|
+
result: rawResult.data,
|
|
640
650
|
dataId: "ROOT_SUBSCRIPTION",
|
|
641
651
|
variables: variables,
|
|
642
652
|
});
|
|
643
653
|
}
|
|
644
654
|
this.broadcastQueries();
|
|
645
655
|
}
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
656
|
+
const result = {
|
|
657
|
+
data: rawResult.data ?? undefined,
|
|
658
|
+
};
|
|
659
|
+
if ((0, utilities_4.graphQLResultHasError)(rawResult)) {
|
|
660
|
+
result.error = new errors_1.CombinedGraphQLErrors(rawResult);
|
|
661
|
+
}
|
|
662
|
+
else if ((0, errors_1.graphQLResultHasProtocolErrors)(rawResult)) {
|
|
663
|
+
result.error = rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
|
|
664
|
+
// Don't emit protocol errors added by HttpLink
|
|
665
|
+
delete rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
|
|
650
666
|
}
|
|
651
|
-
if (
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
667
|
+
if (rawResult.extensions &&
|
|
668
|
+
Object.keys(rawResult.extensions).length) {
|
|
669
|
+
result.extensions = rawResult.extensions;
|
|
670
|
+
}
|
|
671
|
+
if (result.error && errorPolicy === "none") {
|
|
672
|
+
result.data = undefined;
|
|
656
673
|
}
|
|
657
674
|
if (errorPolicy === "ignore") {
|
|
658
|
-
delete result.
|
|
675
|
+
delete result.error;
|
|
659
676
|
}
|
|
660
677
|
return result;
|
|
661
678
|
}), (0, rxjs_1.catchError)((error) => {
|
|
662
|
-
|
|
663
|
-
|
|
679
|
+
if (errorPolicy === "ignore") {
|
|
680
|
+
return (0, rxjs_1.of)({ data: undefined });
|
|
681
|
+
}
|
|
682
|
+
return (0, rxjs_1.of)({ data: undefined, error: maybeWrapError(error) });
|
|
683
|
+
}), (0, rxjs_1.filter)((result) => !!(result.data || result.error)));
|
|
664
684
|
if (this.getDocumentInfo(query).hasClientExports) {
|
|
665
685
|
const observablePromise = this.localState
|
|
666
686
|
.addExportedVariables(query, variables, context)
|
|
@@ -773,7 +793,7 @@ class QueryManager {
|
|
|
773
793
|
queryInfo.resetLastWrite();
|
|
774
794
|
queryInfo.reset();
|
|
775
795
|
// Throwing here effectively calls observer.error.
|
|
776
|
-
throw new errors_1.CombinedGraphQLErrors(
|
|
796
|
+
throw new errors_1.CombinedGraphQLErrors(result);
|
|
777
797
|
}
|
|
778
798
|
// Use linkDocument rather than queryInfo.document so the
|
|
779
799
|
// operation/fragments used to write the result are the same as the
|
|
@@ -794,7 +814,7 @@ class QueryManager {
|
|
|
794
814
|
aqr.data = void 0;
|
|
795
815
|
}
|
|
796
816
|
if (hasErrors && errorPolicy !== "ignore") {
|
|
797
|
-
aqr.error = new errors_1.CombinedGraphQLErrors(
|
|
817
|
+
aqr.error = new errors_1.CombinedGraphQLErrors(result);
|
|
798
818
|
aqr.networkStatus = networkStatus_js_1.NetworkStatus.error;
|
|
799
819
|
}
|
|
800
820
|
return aqr;
|
|
@@ -1031,7 +1051,7 @@ class QueryManager {
|
|
|
1031
1051
|
!(0, utilities_3.isFullyUnmaskedOperation)(document) &&
|
|
1032
1052
|
!this.noCacheWarningsByQueryId.has(operationId)) {
|
|
1033
1053
|
this.noCacheWarningsByQueryId.add(operationId);
|
|
1034
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
1054
|
+
__DEV__ && invariant_1.invariant.warn(80, (0, utilities_4.getOperationName)(document) ??
|
|
1035
1055
|
`Unnamed ${operationType ?? "operation"}`);
|
|
1036
1056
|
}
|
|
1037
1057
|
}
|
|
@@ -1121,7 +1141,7 @@ class QueryManager {
|
|
|
1121
1141
|
context,
|
|
1122
1142
|
fetchPolicy,
|
|
1123
1143
|
errorPolicy,
|
|
1124
|
-
});
|
|
1144
|
+
}).pipe(validateDidEmitValue());
|
|
1125
1145
|
switch (fetchPolicy) {
|
|
1126
1146
|
default:
|
|
1127
1147
|
case "cache-first": {
|
|
@@ -1211,4 +1231,15 @@ function maybeWrapError(error) {
|
|
|
1211
1231
|
}
|
|
1212
1232
|
return new errors_1.UnconventionalError(error);
|
|
1213
1233
|
}
|
|
1234
|
+
function validateDidEmitValue() {
|
|
1235
|
+
let didEmitValue = false;
|
|
1236
|
+
return (0, rxjs_1.tap)({
|
|
1237
|
+
next() {
|
|
1238
|
+
didEmitValue = true;
|
|
1239
|
+
},
|
|
1240
|
+
complete() {
|
|
1241
|
+
(0, invariant_1.invariant)(didEmitValue, 81);
|
|
1242
|
+
},
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1214
1245
|
//# sourceMappingURL=QueryManager.cjs.map
|