@apollo/client 4.0.0-alpha.21 → 4.0.0-alpha.22
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/CHANGELOG.md +103 -0
- package/__cjs/core/ApolloClient.cjs +13 -10
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +7 -8
- package/__cjs/core/ObservableQuery.cjs +5 -5
- package/__cjs/core/QueryManager.cjs +18 -13
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +13 -6
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +1 -1
- package/__cjs/core/types.d.cts +5 -4
- package/__cjs/invariantErrorCodes.cjs +79 -79
- package/__cjs/link/batch-http/batchHttpLink.cjs +14 -14
- package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
- package/__cjs/link/batch-http/batchHttpLink.d.cts +4 -0
- package/__cjs/link/batch-http/index.cjs +2 -1
- package/__cjs/link/batch-http/index.cjs.map +1 -1
- package/__cjs/link/batch-http/index.d.cts +1 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +45 -0
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -0
- package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +62 -0
- package/__cjs/link/client-awareness/index.cjs +6 -0
- package/__cjs/link/client-awareness/index.cjs.map +1 -0
- package/__cjs/link/client-awareness/index.d.cts +2 -0
- package/__cjs/link/core/types.d.cts +1 -6
- package/__cjs/link/http/BaseHttpLink.cjs +117 -0
- package/__cjs/link/http/BaseHttpLink.cjs.map +1 -0
- package/__cjs/link/http/BaseHttpLink.d.cts +6 -0
- package/__cjs/link/http/HttpLink.cjs +8 -5
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +16 -4
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/index.cjs +4 -3
- package/__cjs/link/http/index.cjs.map +1 -1
- package/__cjs/link/http/index.d.cts +2 -2
- package/__cjs/link/http/selectHttpOptionsAndBody.cjs +6 -5
- package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
- package/__cjs/link/persisted-queries/index.cjs +9 -7
- package/__cjs/link/persisted-queries/index.cjs.map +1 -1
- package/__cjs/link/utils/validateOperation.cjs +1 -1
- package/__cjs/local-state/LocalState.cjs +10 -18
- package/__cjs/local-state/LocalState.cjs.map +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 +3 -3
- package/__cjs/react/context/ApolloConsumer.cjs +1 -1
- package/__cjs/react/context/ApolloContext.cjs +1 -1
- package/__cjs/react/context/ApolloProvider.cjs +1 -1
- package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
- package/__cjs/react/hooks/useApolloClient.cjs +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
- package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
- package/__cjs/react/hooks/useSubscription.cjs +1 -1
- package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
- package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
- package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
- package/__cjs/testing/core/mocking/mockLink.cjs +4 -4
- package/__cjs/utilities/caching/sizes.cjs.map +1 -1
- package/__cjs/utilities/caching/sizes.d.cts +6 -0
- package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
- package/__cjs/utilities/internal/checkDocument.cjs +47 -13
- package/__cjs/utilities/internal/checkDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/checkDocument.d.cts +1 -1
- package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs +1 -1
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +2 -2
- package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
- package/__cjs/utilities/internal/getMemoryInternals.cjs +1 -0
- package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
- package/__cjs/utilities/internal/getMemoryInternals.d.cts +0 -1
- package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
- package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
- package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
- package/__cjs/version.cjs +1 -1
- package/core/ApolloClient.d.ts +7 -8
- package/core/ApolloClient.js +14 -11
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.js +5 -5
- package/core/QueryManager.d.ts +13 -6
- package/core/QueryManager.js +18 -13
- package/core/QueryManager.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js.map +1 -1
- package/core/types.d.ts +5 -4
- package/invariantErrorCodes.js +79 -79
- package/legacyEntryPoints/link/client-awareness/client-awareness.cjs +1 -0
- package/legacyEntryPoints/link/client-awareness/client-awareness.d.cts +1 -0
- package/legacyEntryPoints/link/client-awareness/index.d.ts +1 -0
- package/legacyEntryPoints/link/client-awareness/index.js +1 -0
- package/link/batch-http/batchHttpLink.d.ts +4 -0
- package/link/batch-http/batchHttpLink.js +11 -12
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/batch-http/index.d.ts +1 -1
- package/link/batch-http/index.js +1 -1
- package/link/batch-http/index.js.map +1 -1
- package/link/client-awareness/ClientAwarenessLink.d.ts +62 -0
- package/link/client-awareness/ClientAwarenessLink.js +41 -0
- package/link/client-awareness/ClientAwarenessLink.js.map +1 -0
- package/link/client-awareness/index.d.ts +2 -0
- package/link/client-awareness/index.js +2 -0
- package/link/client-awareness/index.js.map +1 -0
- package/link/core/types.d.ts +1 -6
- package/link/http/BaseHttpLink.d.ts +6 -0
- package/link/http/BaseHttpLink.js +113 -0
- package/link/http/BaseHttpLink.js.map +1 -0
- package/link/http/HttpLink.d.ts +16 -4
- package/link/http/HttpLink.js +6 -4
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/checkFetcher.js +1 -1
- package/link/http/index.d.ts +2 -2
- package/link/http/index.js +2 -2
- package/link/http/index.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +6 -5
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/persisted-queries/index.js +9 -7
- package/link/persisted-queries/index.js.map +1 -1
- package/link/utils/validateOperation.js +1 -1
- package/local-state/LocalState.js +10 -18
- package/local-state/LocalState.js.map +1 -1
- package/masking/maskDefinition.js +2 -2
- package/masking/maskFragment.js +2 -2
- package/masking/maskOperation.js +1 -1
- package/masking/utils.js +3 -3
- package/package.json +7 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useLazyQuery.js +2 -2
- package/react/hooks/useLoadableQuery.js +2 -2
- package/react/hooks/useSubscription.js +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/ssr/prerenderStatic.js +2 -2
- package/testing/core/mocking/mockLink.js +4 -4
- package/utilities/caching/sizes.d.ts +6 -0
- package/utilities/caching/sizes.js.map +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/internal/checkDocument.d.ts +1 -1
- package/utilities/internal/checkDocument.js +46 -12
- package/utilities/internal/checkDocument.js.map +1 -1
- package/utilities/internal/getFragmentDefinition.js +3 -3
- package/utilities/internal/getFragmentFromSelection.js +1 -1
- package/utilities/internal/getFragmentQueryDocument.js +2 -2
- package/utilities/internal/getMainDefinition.js +1 -1
- package/utilities/internal/getMemoryInternals.d.ts +0 -1
- package/utilities/internal/getMemoryInternals.js +1 -0
- package/utilities/internal/getMemoryInternals.js.map +1 -1
- package/utilities/internal/getQueryDefinition.js +1 -1
- package/utilities/internal/removeDirectivesFromDocument.js +1 -1
- package/utilities/internal/shouldInclude.js +4 -4
- package/utilities/internal/valueToObjectRepresentation.js +1 -1
- package/version.js +1 -1
- package/__cjs/link/http/createHttpLink.cjs +0 -151
- package/__cjs/link/http/createHttpLink.cjs.map +0 -1
- package/__cjs/link/http/createHttpLink.d.cts +0 -4
- package/link/http/createHttpLink.d.ts +0 -4
- package/link/http/createHttpLink.js +0 -143
- package/link/http/createHttpLink.js.map +0 -1
package/core/QueryManager.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ import type { FetchResult } from "@apollo/client/link";
|
|
|
7
7
|
import type { LocalState } from "@apollo/client/local-state";
|
|
8
8
|
import type { MaybeMasked } from "@apollo/client/masking";
|
|
9
9
|
import { DocumentTransform } from "@apollo/client/utilities";
|
|
10
|
-
import type { ApolloClient, DefaultOptions } from "./ApolloClient.js";
|
|
10
|
+
import type { ApolloClient, ApolloClientOptions, DefaultOptions } from "./ApolloClient.js";
|
|
11
11
|
import { NetworkStatus } from "./networkStatus.js";
|
|
12
12
|
import { ObservableQuery } from "./ObservableQuery.js";
|
|
13
|
-
import type {
|
|
14
|
-
import type { MutationOptions, QueryOptions, SubscriptionOptions, WatchQueryFetchPolicy, WatchQueryOptions } from "./watchQueryOptions.js";
|
|
13
|
+
import type { DefaultContext, InternalRefetchQueriesInclude, InternalRefetchQueriesMap, InternalRefetchQueriesOptions, MutateResult, OperationVariables, QueryNotification, QueryResult, SubscribeResult, SubscriptionObservable } from "./types.js";
|
|
14
|
+
import type { ErrorPolicy, MutationFetchPolicy, MutationOptions, QueryOptions, SubscriptionOptions, WatchQueryFetchPolicy, WatchQueryOptions } from "./watchQueryOptions.js";
|
|
15
15
|
interface MutationStoreValue {
|
|
16
16
|
mutation: DocumentNode;
|
|
17
17
|
variables: Record<string, any>;
|
|
@@ -28,6 +28,7 @@ interface TransformCacheEntry {
|
|
|
28
28
|
defaultVars: OperationVariables;
|
|
29
29
|
asQuery: DocumentNode;
|
|
30
30
|
operationType: OperationTypeNode | undefined;
|
|
31
|
+
violation?: Error | undefined;
|
|
31
32
|
}
|
|
32
33
|
interface MaskFragmentOptions<TData> {
|
|
33
34
|
fragment: DocumentNode;
|
|
@@ -47,12 +48,12 @@ interface MaskOperationOptions<TData> {
|
|
|
47
48
|
}
|
|
48
49
|
interface QueryManagerOptions {
|
|
49
50
|
client: ApolloClient;
|
|
51
|
+
clientOptions: ApolloClientOptions;
|
|
50
52
|
defaultOptions: DefaultOptions;
|
|
51
53
|
documentTransform: DocumentTransform | null | undefined;
|
|
52
54
|
queryDeduplication: boolean;
|
|
53
55
|
onBroadcast: undefined | (() => void);
|
|
54
56
|
ssrMode: boolean;
|
|
55
|
-
clientAwareness: ClientAwareness;
|
|
56
57
|
assumeImmutableResults: boolean;
|
|
57
58
|
defaultContext: Partial<DefaultContext> | undefined;
|
|
58
59
|
dataMasking: boolean;
|
|
@@ -61,6 +62,10 @@ interface QueryManagerOptions {
|
|
|
61
62
|
export declare class QueryManager {
|
|
62
63
|
defaultOptions: DefaultOptions;
|
|
63
64
|
readonly client: ApolloClient;
|
|
65
|
+
/**
|
|
66
|
+
* The options that were passed to the ApolloClient constructor.
|
|
67
|
+
*/
|
|
68
|
+
readonly clientOptions: ApolloClientOptions;
|
|
64
69
|
readonly assumeImmutableResults: boolean;
|
|
65
70
|
readonly documentTransform: DocumentTransform;
|
|
66
71
|
readonly ssrMode: boolean;
|
|
@@ -68,7 +73,6 @@ export declare class QueryManager {
|
|
|
68
73
|
readonly dataMasking: boolean;
|
|
69
74
|
localState: LocalState | undefined;
|
|
70
75
|
private queryDeduplication;
|
|
71
|
-
private clientAwareness;
|
|
72
76
|
/**
|
|
73
77
|
* Whether to prioritize cache values over network results when
|
|
74
78
|
* `fetchObservableWithInfo` is called.
|
|
@@ -98,7 +102,10 @@ export declare class QueryManager {
|
|
|
98
102
|
*/
|
|
99
103
|
stop(): void;
|
|
100
104
|
private cancelPendingFetches;
|
|
101
|
-
mutate<TData, TVariables extends OperationVariables, TCache extends ApolloCache>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TCache>
|
|
105
|
+
mutate<TData, TVariables extends OperationVariables, TCache extends ApolloCache>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TCache> & {
|
|
106
|
+
errorPolicy: ErrorPolicy;
|
|
107
|
+
fetchPolicy: MutationFetchPolicy;
|
|
108
|
+
}): Promise<MutateResult<MaybeMasked<TData>>>;
|
|
102
109
|
fetchQuery<TData, TVars extends OperationVariables>(options: WatchQueryOptions<TVars, TData>, networkStatus?: NetworkStatus): Promise<QueryResult<TData>>;
|
|
103
110
|
transform(document: DocumentNode): DocumentNode;
|
|
104
111
|
private transformCache;
|
package/core/QueryManager.js
CHANGED
|
@@ -17,6 +17,10 @@ import { QueryInfo } from "./QueryInfo.js";
|
|
|
17
17
|
export class QueryManager {
|
|
18
18
|
defaultOptions;
|
|
19
19
|
client;
|
|
20
|
+
/**
|
|
21
|
+
* The options that were passed to the ApolloClient constructor.
|
|
22
|
+
*/
|
|
23
|
+
clientOptions;
|
|
20
24
|
assumeImmutableResults;
|
|
21
25
|
documentTransform;
|
|
22
26
|
ssrMode;
|
|
@@ -24,7 +28,6 @@ export class QueryManager {
|
|
|
24
28
|
dataMasking;
|
|
25
29
|
localState;
|
|
26
30
|
queryDeduplication;
|
|
27
|
-
clientAwareness = {};
|
|
28
31
|
/**
|
|
29
32
|
* Whether to prioritize cache values over network results when
|
|
30
33
|
* `fetchObservableWithInfo` is called.
|
|
@@ -54,7 +57,7 @@ export class QueryManager {
|
|
|
54
57
|
this.client = options.client;
|
|
55
58
|
this.defaultOptions = options.defaultOptions;
|
|
56
59
|
this.queryDeduplication = options.queryDeduplication;
|
|
57
|
-
this.
|
|
60
|
+
this.clientOptions = options.clientOptions;
|
|
58
61
|
this.ssrMode = options.ssrMode;
|
|
59
62
|
this.assumeImmutableResults = options.assumeImmutableResults;
|
|
60
63
|
this.dataMasking = options.dataMasking;
|
|
@@ -87,16 +90,13 @@ export class QueryManager {
|
|
|
87
90
|
*/
|
|
88
91
|
stop() {
|
|
89
92
|
this.obsQueries.forEach((oq) => oq.stop());
|
|
90
|
-
this.cancelPendingFetches(newInvariantError(
|
|
93
|
+
this.cancelPendingFetches(newInvariantError(83));
|
|
91
94
|
}
|
|
92
95
|
cancelPendingFetches(error) {
|
|
93
96
|
this.fetchCancelFns.forEach((cancel) => cancel(error));
|
|
94
97
|
this.fetchCancelFns.clear();
|
|
95
98
|
}
|
|
96
|
-
async mutate({ mutation, variables, optimisticResponse, updateQueries, refetchQueries = [], awaitRefetchQueries = false, update: updateWithProxyFn, onQueryUpdated, fetchPolicy
|
|
97
|
-
invariant(mutation, 82);
|
|
98
|
-
checkDocument(mutation, OperationTypeNode.MUTATION);
|
|
99
|
-
invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 83);
|
|
99
|
+
async mutate({ mutation, variables, optimisticResponse, updateQueries, refetchQueries = [], awaitRefetchQueries = false, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }) {
|
|
100
100
|
const queryInfo = new QueryInfo(this);
|
|
101
101
|
mutation = this.cache.transformForLink(this.transform(mutation));
|
|
102
102
|
const { hasClientExports } = this.getDocumentInfo(mutation);
|
|
@@ -219,7 +219,10 @@ export class QueryManager {
|
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
fetchQuery(options, networkStatus) {
|
|
222
|
-
|
|
222
|
+
checkDocument(options.query, OperationTypeNode.QUERY);
|
|
223
|
+
// do the rest asynchronously to keep the same rejection timing as
|
|
224
|
+
// checks further in `.mutate`
|
|
225
|
+
return (async () => lastValueFrom(this.fetchObservableWithInfo(options, {
|
|
223
226
|
networkStatus,
|
|
224
227
|
}).observable.pipe(filterMap((value) => {
|
|
225
228
|
switch (value.kind) {
|
|
@@ -234,7 +237,7 @@ export class QueryManager {
|
|
|
234
237
|
// This default is needed when a `standby` fetch policy is used to avoid
|
|
235
238
|
// an EmptyError from rejecting this promise.
|
|
236
239
|
defaultValue: { data: undefined },
|
|
237
|
-
});
|
|
240
|
+
}))();
|
|
238
241
|
}
|
|
239
242
|
transform(document) {
|
|
240
243
|
return this.documentTransform.transformDocument(document);
|
|
@@ -279,7 +282,11 @@ export class QueryManager {
|
|
|
279
282
|
};
|
|
280
283
|
transformCache.set(document, cacheEntry);
|
|
281
284
|
}
|
|
282
|
-
|
|
285
|
+
const entry = transformCache.get(document);
|
|
286
|
+
if (entry.violation) {
|
|
287
|
+
throw entry.violation;
|
|
288
|
+
}
|
|
289
|
+
return entry;
|
|
283
290
|
}
|
|
284
291
|
getVariables(document, variables) {
|
|
285
292
|
const defaultVars = this.getDocumentInfo(document).defaultVars;
|
|
@@ -309,7 +316,7 @@ export class QueryManager {
|
|
|
309
316
|
});
|
|
310
317
|
return observable;
|
|
311
318
|
}
|
|
312
|
-
|
|
319
|
+
query(options) {
|
|
313
320
|
const query = this.transform(options.query);
|
|
314
321
|
return this.fetchQuery({
|
|
315
322
|
...options,
|
|
@@ -520,7 +527,6 @@ export class QueryManager {
|
|
|
520
527
|
...this.defaultContext,
|
|
521
528
|
...context,
|
|
522
529
|
queryDeduplication: deduplication,
|
|
523
|
-
clientAwareness: this.clientAwareness,
|
|
524
530
|
},
|
|
525
531
|
extensions,
|
|
526
532
|
};
|
|
@@ -1086,7 +1092,6 @@ function isFullyUnmaskedOperation(document) {
|
|
|
1086
1092
|
return isUnmasked;
|
|
1087
1093
|
}
|
|
1088
1094
|
function addNonReactiveToNamedFragments(document) {
|
|
1089
|
-
checkDocument(document);
|
|
1090
1095
|
return visit(document, {
|
|
1091
1096
|
FragmentSpread: (node) => {
|
|
1092
1097
|
// Do not add `@nonreactive` if the fragment is marked with `@unmask`
|