@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
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, QueryResult, 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;
|
|
@@ -89,7 +89,7 @@ export declare class QueryManager {
|
|
|
89
89
|
*/
|
|
90
90
|
stop(): void;
|
|
91
91
|
private cancelPendingFetches;
|
|
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<
|
|
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>>>;
|
|
93
93
|
markMutationResult<TData, TVariables extends OperationVariables, TContext, TCache extends ApolloCache>(mutation: {
|
|
94
94
|
mutationId: string;
|
|
95
95
|
result: FetchResult<TData>;
|
|
@@ -117,13 +117,13 @@ export declare class QueryManager {
|
|
|
117
117
|
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
|
|
118
118
|
keepRootFields?: boolean;
|
|
119
119
|
}): boolean;
|
|
120
|
-
fetchQuery<TData, TVars extends OperationVariables>(queryId: string, options: WatchQueryOptions<TVars, TData>, networkStatus?: NetworkStatus): Promise<
|
|
120
|
+
fetchQuery<TData, TVars extends OperationVariables>(queryId: string, options: WatchQueryOptions<TVars, TData>, networkStatus?: NetworkStatus): Promise<QueryResult<TData>>;
|
|
121
121
|
transform(document: DocumentNode): DocumentNode;
|
|
122
122
|
private transformCache;
|
|
123
123
|
getDocumentInfo(document: DocumentNode): TransformCacheEntry;
|
|
124
124
|
private getVariables;
|
|
125
125
|
watchQuery<T, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
|
|
126
|
-
query<TData, TVars extends OperationVariables = OperationVariables>(options: QueryOptions<TVars, TData>, queryId?: string): Promise<
|
|
126
|
+
query<TData, TVars extends OperationVariables = OperationVariables>(options: QueryOptions<TVars, TData>, queryId?: string): Promise<QueryResult<MaybeMasked<TData>>>;
|
|
127
127
|
private queryIdCounter;
|
|
128
128
|
generateQueryId(): string;
|
|
129
129
|
private requestIdCounter;
|
|
@@ -132,9 +132,9 @@ export declare class QueryManager {
|
|
|
132
132
|
generateMutationId(): string;
|
|
133
133
|
clearStore(options?: Cache.ResetOptions): Promise<void>;
|
|
134
134
|
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
|
|
135
|
-
reFetchObservableQueries(includeStandby?: boolean): Promise<
|
|
135
|
+
reFetchObservableQueries(includeStandby?: boolean): Promise<QueryResult<any>[]>;
|
|
136
136
|
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
|
|
137
|
-
startGraphQLSubscription<TData = unknown>(options: SubscriptionOptions): Observable<
|
|
137
|
+
startGraphQLSubscription<TData = unknown>(options: SubscriptionOptions): Observable<SubscribeResult<TData>>;
|
|
138
138
|
stopQuery(queryId: string): void;
|
|
139
139
|
removeQuery(queryId: string): void;
|
|
140
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";
|
|
@@ -11,7 +11,7 @@ import { addNonReactiveToNamedFragments, hasDirectives, isExecutionPatchIncremen
|
|
|
11
11
|
import { DocumentTransform, getDefaultValues, getGraphQLErrorsFromResult, getOperationDefinition, getOperationName, graphQLResultHasError, hasClientExports, isDocumentNode, isNonEmptyArray, isNonNullObject, makeUniqueId, } from "@apollo/client/utilities";
|
|
12
12
|
import { mergeIncrementalData } from "@apollo/client/utilities";
|
|
13
13
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
14
|
-
import { onAnyEvent } from "@apollo/client/utilities/internal";
|
|
14
|
+
import { onAnyEvent, toQueryResult } from "@apollo/client/utilities/internal";
|
|
15
15
|
import { invariant, newInvariantError, } from "@apollo/client/utilities/invariant";
|
|
16
16
|
import { isNetworkRequestInFlight, NetworkStatus } from "./networkStatus.js";
|
|
17
17
|
import { logMissingFieldErrors, ObservableQuery } from "./ObservableQuery.js";
|
|
@@ -88,15 +88,15 @@ export class QueryManager {
|
|
|
88
88
|
this.queries.forEach((_info, queryId) => {
|
|
89
89
|
this.removeQuery(queryId);
|
|
90
90
|
});
|
|
91
|
-
this.cancelPendingFetches(newInvariantError(
|
|
91
|
+
this.cancelPendingFetches(newInvariantError(74));
|
|
92
92
|
}
|
|
93
93
|
cancelPendingFetches(error) {
|
|
94
94
|
this.fetchCancelFns.forEach((cancel) => cancel(error));
|
|
95
95
|
this.fetchCancelFns.clear();
|
|
96
96
|
}
|
|
97
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, }) {
|
|
98
|
-
invariant(mutation,
|
|
99
|
-
invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache",
|
|
98
|
+
invariant(mutation, 75);
|
|
99
|
+
invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 76);
|
|
100
100
|
const mutationId = this.generateMutationId();
|
|
101
101
|
mutation = this.cache.transformForLink(this.transform(mutation));
|
|
102
102
|
const { hasClientExports } = this.getDocumentInfo(mutation);
|
|
@@ -129,9 +129,10 @@ export class QueryManager {
|
|
|
129
129
|
...context,
|
|
130
130
|
optimisticResponse: isOptimistic ? optimisticResponse : void 0,
|
|
131
131
|
}, variables, {}, false)
|
|
132
|
-
.pipe(mergeMap((result) => {
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
.pipe(validateDidEmitValue(), mergeMap((result) => {
|
|
133
|
+
const hasErrors = graphQLResultHasError(result);
|
|
134
|
+
if (hasErrors && errorPolicy === "none") {
|
|
135
|
+
throw new CombinedGraphQLErrors(result);
|
|
135
136
|
}
|
|
136
137
|
if (mutationStoreValue) {
|
|
137
138
|
mutationStoreValue.loading = false;
|
|
@@ -141,8 +142,7 @@ export class QueryManager {
|
|
|
141
142
|
if (typeof refetchQueries === "function") {
|
|
142
143
|
refetchQueries = refetchQueries(storeResult);
|
|
143
144
|
}
|
|
144
|
-
if (errorPolicy === "ignore" &&
|
|
145
|
-
graphQLResultHasError(storeResult)) {
|
|
145
|
+
if (errorPolicy === "ignore" && hasErrors) {
|
|
146
146
|
delete storeResult.errors;
|
|
147
147
|
}
|
|
148
148
|
return from(this.markMutationResult({
|
|
@@ -171,28 +171,40 @@ export class QueryManager {
|
|
|
171
171
|
// ExecutionPatchResult has arrived and we have assembled the
|
|
172
172
|
// multipart response into a single result.
|
|
173
173
|
if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
|
|
174
|
-
|
|
175
|
-
...storeResult,
|
|
174
|
+
const result = {
|
|
176
175
|
data: this.maskOperation({
|
|
177
176
|
document: mutation,
|
|
178
177
|
data: storeResult.data,
|
|
179
178
|
fetchPolicy,
|
|
180
179
|
id: mutationId,
|
|
181
180
|
}),
|
|
182
|
-
}
|
|
181
|
+
};
|
|
182
|
+
if (graphQLResultHasError(storeResult)) {
|
|
183
|
+
result.error = new CombinedGraphQLErrors(storeResult);
|
|
184
|
+
}
|
|
185
|
+
if (storeResult.extensions) {
|
|
186
|
+
result.extensions = storeResult.extensions;
|
|
187
|
+
}
|
|
188
|
+
resolve(result);
|
|
183
189
|
}
|
|
184
190
|
},
|
|
185
191
|
error: (err) => {
|
|
186
|
-
|
|
192
|
+
const error = maybeWrapError(err);
|
|
187
193
|
if (mutationStoreValue) {
|
|
188
194
|
mutationStoreValue.loading = false;
|
|
189
|
-
mutationStoreValue.error =
|
|
195
|
+
mutationStoreValue.error = error;
|
|
190
196
|
}
|
|
191
197
|
if (isOptimistic) {
|
|
192
198
|
this.cache.removeOptimistic(mutationId);
|
|
193
199
|
}
|
|
194
200
|
this.broadcastQueries();
|
|
195
|
-
|
|
201
|
+
if (errorPolicy === "ignore") {
|
|
202
|
+
return resolve({ data: undefined });
|
|
203
|
+
}
|
|
204
|
+
if (errorPolicy === "all") {
|
|
205
|
+
return resolve({ data: undefined, error });
|
|
206
|
+
}
|
|
207
|
+
reject(error);
|
|
196
208
|
},
|
|
197
209
|
});
|
|
198
210
|
});
|
|
@@ -382,7 +394,11 @@ export class QueryManager {
|
|
|
382
394
|
return true;
|
|
383
395
|
}
|
|
384
396
|
fetchQuery(queryId, options, networkStatus) {
|
|
385
|
-
return lastValueFrom(this.fetchObservableWithInfo(queryId, options, networkStatus).observable, {
|
|
397
|
+
return lastValueFrom(this.fetchObservableWithInfo(queryId, options, networkStatus).observable.pipe(map(toQueryResult)), {
|
|
398
|
+
// This default is needed when a `standby` fetch policy is used to avoid
|
|
399
|
+
// an EmptyError from rejecting this promise.
|
|
400
|
+
defaultValue: { data: undefined },
|
|
401
|
+
});
|
|
386
402
|
}
|
|
387
403
|
transform(document) {
|
|
388
404
|
return this.documentTransform.transformDocument(document);
|
|
@@ -462,24 +478,18 @@ export class QueryManager {
|
|
|
462
478
|
});
|
|
463
479
|
return observable;
|
|
464
480
|
}
|
|
465
|
-
// TODO: catch `EmptyError` and rethrow as network error if `complete`
|
|
466
|
-
// notification is emitted without a value.
|
|
467
481
|
query(options, queryId = this.generateQueryId()) {
|
|
468
|
-
invariant(options.query, 75);
|
|
469
|
-
invariant(options.query.kind === "Document", 76);
|
|
470
|
-
invariant(!options.returnPartialData, 77);
|
|
471
|
-
invariant(!options.pollInterval, 78);
|
|
472
482
|
const query = this.transform(options.query);
|
|
473
483
|
return this.fetchQuery(queryId, { ...options, query })
|
|
474
|
-
.then((
|
|
475
|
-
...
|
|
484
|
+
.then((value) => ({
|
|
485
|
+
...value,
|
|
476
486
|
data: this.maskOperation({
|
|
477
487
|
document: query,
|
|
478
|
-
data:
|
|
488
|
+
data: value?.data,
|
|
479
489
|
fetchPolicy: options.fetchPolicy,
|
|
480
490
|
id: queryId,
|
|
481
491
|
}),
|
|
482
|
-
})
|
|
492
|
+
}))
|
|
483
493
|
.finally(() => this.stopQuery(queryId));
|
|
484
494
|
}
|
|
485
495
|
queryIdCounter = 1;
|
|
@@ -502,7 +512,7 @@ export class QueryManager {
|
|
|
502
512
|
// depend on values that previously existed in the data portion of the
|
|
503
513
|
// store. So, we cancel the promises and observers that we have issued
|
|
504
514
|
// so far and not yet resolved (in the case of queries).
|
|
505
|
-
this.cancelPendingFetches(newInvariantError(
|
|
515
|
+
this.cancelPendingFetches(newInvariantError(77));
|
|
506
516
|
this.queries.forEach((queryInfo) => {
|
|
507
517
|
if (queryInfo.observableQuery) {
|
|
508
518
|
// Set loading to true so listeners don't trigger unless they want
|
|
@@ -590,10 +600,10 @@ export class QueryManager {
|
|
|
590
600
|
if (!included) {
|
|
591
601
|
const queryName = queryNames.get(nameOrQueryString);
|
|
592
602
|
if (queryName) {
|
|
593
|
-
__DEV__ && invariant.warn(
|
|
603
|
+
__DEV__ && invariant.warn(78, queryName);
|
|
594
604
|
}
|
|
595
605
|
else {
|
|
596
|
-
__DEV__ && invariant.warn(
|
|
606
|
+
__DEV__ && invariant.warn(79);
|
|
597
607
|
}
|
|
598
608
|
}
|
|
599
609
|
});
|
|
@@ -622,38 +632,48 @@ export class QueryManager {
|
|
|
622
632
|
const { fetchPolicy, errorPolicy = "none", context = {}, extensions = {}, } = options;
|
|
623
633
|
query = this.transform(query);
|
|
624
634
|
variables = this.getVariables(query, variables);
|
|
625
|
-
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe(map((
|
|
635
|
+
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe(map((rawResult) => {
|
|
626
636
|
if (fetchPolicy !== "no-cache") {
|
|
627
637
|
// the subscription interface should handle not sending us results we no longer subscribe to.
|
|
628
638
|
// XXX I don't think we ever send in an object with errors, but we might in the future...
|
|
629
|
-
if (shouldWriteResult(
|
|
639
|
+
if (shouldWriteResult(rawResult, errorPolicy)) {
|
|
630
640
|
this.cache.write({
|
|
631
641
|
query,
|
|
632
|
-
result:
|
|
642
|
+
result: rawResult.data,
|
|
633
643
|
dataId: "ROOT_SUBSCRIPTION",
|
|
634
644
|
variables: variables,
|
|
635
645
|
});
|
|
636
646
|
}
|
|
637
647
|
this.broadcastQueries();
|
|
638
648
|
}
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
649
|
+
const result = {
|
|
650
|
+
data: rawResult.data ?? undefined,
|
|
651
|
+
};
|
|
652
|
+
if (graphQLResultHasError(rawResult)) {
|
|
653
|
+
result.error = new CombinedGraphQLErrors(rawResult);
|
|
654
|
+
}
|
|
655
|
+
else if (graphQLResultHasProtocolErrors(rawResult)) {
|
|
656
|
+
result.error = rawResult.extensions[PROTOCOL_ERRORS_SYMBOL];
|
|
657
|
+
// Don't emit protocol errors added by HttpLink
|
|
658
|
+
delete rawResult.extensions[PROTOCOL_ERRORS_SYMBOL];
|
|
643
659
|
}
|
|
644
|
-
if (
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
660
|
+
if (rawResult.extensions &&
|
|
661
|
+
Object.keys(rawResult.extensions).length) {
|
|
662
|
+
result.extensions = rawResult.extensions;
|
|
663
|
+
}
|
|
664
|
+
if (result.error && errorPolicy === "none") {
|
|
665
|
+
result.data = undefined;
|
|
649
666
|
}
|
|
650
667
|
if (errorPolicy === "ignore") {
|
|
651
|
-
delete result.
|
|
668
|
+
delete result.error;
|
|
652
669
|
}
|
|
653
670
|
return result;
|
|
654
671
|
}), catchError((error) => {
|
|
655
|
-
|
|
656
|
-
|
|
672
|
+
if (errorPolicy === "ignore") {
|
|
673
|
+
return of({ data: undefined });
|
|
674
|
+
}
|
|
675
|
+
return of({ data: undefined, error: maybeWrapError(error) });
|
|
676
|
+
}), filter((result) => !!(result.data || result.error)));
|
|
657
677
|
if (this.getDocumentInfo(query).hasClientExports) {
|
|
658
678
|
const observablePromise = this.localState
|
|
659
679
|
.addExportedVariables(query, variables, context)
|
|
@@ -766,7 +786,7 @@ export class QueryManager {
|
|
|
766
786
|
queryInfo.resetLastWrite();
|
|
767
787
|
queryInfo.reset();
|
|
768
788
|
// Throwing here effectively calls observer.error.
|
|
769
|
-
throw new CombinedGraphQLErrors(
|
|
789
|
+
throw new CombinedGraphQLErrors(result);
|
|
770
790
|
}
|
|
771
791
|
// Use linkDocument rather than queryInfo.document so the
|
|
772
792
|
// operation/fragments used to write the result are the same as the
|
|
@@ -787,7 +807,7 @@ export class QueryManager {
|
|
|
787
807
|
aqr.data = void 0;
|
|
788
808
|
}
|
|
789
809
|
if (hasErrors && errorPolicy !== "ignore") {
|
|
790
|
-
aqr.error = new CombinedGraphQLErrors(
|
|
810
|
+
aqr.error = new CombinedGraphQLErrors(result);
|
|
791
811
|
aqr.networkStatus = NetworkStatus.error;
|
|
792
812
|
}
|
|
793
813
|
return aqr;
|
|
@@ -1024,7 +1044,7 @@ export class QueryManager {
|
|
|
1024
1044
|
!isFullyUnmaskedOperation(document) &&
|
|
1025
1045
|
!this.noCacheWarningsByQueryId.has(operationId)) {
|
|
1026
1046
|
this.noCacheWarningsByQueryId.add(operationId);
|
|
1027
|
-
__DEV__ && invariant.warn(
|
|
1047
|
+
__DEV__ && invariant.warn(80, getOperationName(document) ??
|
|
1028
1048
|
`Unnamed ${operationType ?? "operation"}`);
|
|
1029
1049
|
}
|
|
1030
1050
|
}
|
|
@@ -1114,7 +1134,7 @@ export class QueryManager {
|
|
|
1114
1134
|
context,
|
|
1115
1135
|
fetchPolicy,
|
|
1116
1136
|
errorPolicy,
|
|
1117
|
-
});
|
|
1137
|
+
}).pipe(validateDidEmitValue());
|
|
1118
1138
|
switch (fetchPolicy) {
|
|
1119
1139
|
default:
|
|
1120
1140
|
case "cache-first": {
|
|
@@ -1203,4 +1223,15 @@ function maybeWrapError(error) {
|
|
|
1203
1223
|
}
|
|
1204
1224
|
return new UnconventionalError(error);
|
|
1205
1225
|
}
|
|
1226
|
+
function validateDidEmitValue() {
|
|
1227
|
+
let didEmitValue = false;
|
|
1228
|
+
return tap({
|
|
1229
|
+
next() {
|
|
1230
|
+
didEmitValue = true;
|
|
1231
|
+
},
|
|
1232
|
+
complete() {
|
|
1233
|
+
invariant(didEmitValue, 81);
|
|
1234
|
+
},
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1206
1237
|
//# sourceMappingURL=QueryManager.js.map
|