@apollo/client 4.2.8 → 4.2.10
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 +20 -0
- package/README.md +3 -7
- package/__cjs/cache/inmemory/readFromStore.cjs +1 -4
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +44 -10
- package/__cjs/core/ObservableQuery.cjs +42 -4
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +12 -1
- package/__cjs/core/QueryManager.cjs +12 -0
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/types.d.cts +2 -0
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +92 -47
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +26 -20
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +23 -15
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +10 -7
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +66 -32
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +75 -34
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/types.d.cts +14 -3
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -5
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.cjs.map +1 -1
- package/cache/inmemory/readFromStore.js +2 -5
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/core/ApolloClient.d.ts +44 -10
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +12 -1
- package/core/ObservableQuery.js +42 -4
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.js +12 -0
- package/core/QueryManager.js.map +1 -1
- package/core/types.d.ts +2 -0
- package/core/types.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +92 -47
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +26 -20
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +23 -15
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +10 -7
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +66 -32
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +75 -34
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +92 -47
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +26 -20
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +23 -15
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +10 -7
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +66 -32
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +75 -34
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/types.d.ts +15 -4
- package/react/internal/types.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +20 -5
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -8,7 +8,7 @@ import type { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
|
8
8
|
import type { LocalState } from "@apollo/client/local-state";
|
|
9
9
|
import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
|
|
10
10
|
import { DocumentTransform } from "@apollo/client/utilities";
|
|
11
|
-
import type { LazyType, OptionWithFallback, SignatureStyle, VariablesOption, variablesUnknownSymbol } from "@apollo/client/utilities/internal";
|
|
11
|
+
import type { LazyType, OptionWithFallback, Prettify, SignatureStyle, VariablesOption, variablesUnknownSymbol } from "@apollo/client/utilities/internal";
|
|
12
12
|
import { getApolloClientMemoryInternals } from "@apollo/client/utilities/internal";
|
|
13
13
|
import type { DeclareDefaultOptions, DefaultOptions } from "./defaultOptions.cjs";
|
|
14
14
|
import type { ObservableQuery } from "./ObservableQuery.cjs";
|
|
@@ -232,7 +232,20 @@ export declare namespace ApolloClient {
|
|
|
232
232
|
export namespace mutate {
|
|
233
233
|
interface DefaultOptions extends ApolloClient.DefaultOptions.Mutate.Calculated {
|
|
234
234
|
}
|
|
235
|
-
type
|
|
235
|
+
type OptionsFor<TData, TVariables extends OperationVariables, TCache extends ApolloCache, TOptions extends {
|
|
236
|
+
variables?: unknown;
|
|
237
|
+
}> = MutateOptions<NoInfer<TData>, NoInfer<TVariables>, TCache> & {
|
|
238
|
+
variables?: Prettify<TVariables & {
|
|
239
|
+
[K in keyof TOptions["variables"]]: K extends keyof TVariables ? TVariables[K] : never;
|
|
240
|
+
}>;
|
|
241
|
+
} & (Exclude<keyof TOptions, keyof MutateOptions<any, any, any>> extends (infer InvalidOptionNames extends string) ? [
|
|
242
|
+
InvalidOptionNames
|
|
243
|
+
] extends [never] ? unknown : {
|
|
244
|
+
[K in InvalidOptionNames]: never;
|
|
245
|
+
} : never);
|
|
246
|
+
type ResultForOptions<TData, TErrorPolicy extends ErrorPolicy | undefined = undefined> = LazyType<MutateResult<MaybeMasked<TData>, OptionWithFallback<{
|
|
247
|
+
errorPolicy: TErrorPolicy;
|
|
248
|
+
}, DefaultOptions, "errorPolicy"> & ErrorPolicy>>;
|
|
236
249
|
namespace Signatures {
|
|
237
250
|
interface Classic {
|
|
238
251
|
/**
|
|
@@ -271,11 +284,21 @@ export declare namespace ApolloClient {
|
|
|
271
284
|
*
|
|
272
285
|
* It takes options as an object with the following keys and values:
|
|
273
286
|
*/
|
|
274
|
-
<TData, TVariables extends OperationVariables, TCache extends ApolloCache, TOptions extends ApolloClient.MutateOptions<NoInfer<TData>,
|
|
275
|
-
|
|
276
|
-
}
|
|
287
|
+
<TData, TVariables extends OperationVariables, TCache extends ApolloCache, TOptions extends Omit<ApolloClient.MutateOptions<NoInfer<TData>, any, TCache>, "variables"> & {
|
|
288
|
+
variables?: unknown;
|
|
289
|
+
}, TErrorPolicy extends ErrorPolicy | undefined = undefined>(options: TOptions & ApolloClient.mutate.OptionsFor<TData, TVariables, TCache, TOptions> & {
|
|
277
290
|
mutation: TypedDocumentNode<TData, TVariables>;
|
|
278
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Specifies how the mutation handles a response that returns both GraphQL errors and partial results.
|
|
293
|
+
*
|
|
294
|
+
* For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
|
|
295
|
+
*
|
|
296
|
+
* The default value is `none`, meaning that the mutation result includes error details but _not_ partial results.
|
|
297
|
+
*
|
|
298
|
+
* @docGroup 1. Operation options
|
|
299
|
+
*/
|
|
300
|
+
errorPolicy?: TErrorPolicy;
|
|
301
|
+
}): Promise<ApolloClient.mutate.ResultForOptions<TData, TErrorPolicy>>;
|
|
279
302
|
}
|
|
280
303
|
type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
|
|
281
304
|
}
|
|
@@ -473,7 +496,18 @@ export declare namespace ApolloClient {
|
|
|
473
496
|
export namespace query {
|
|
474
497
|
interface DefaultOptions extends ApolloClient.DefaultOptions.Query.Calculated {
|
|
475
498
|
}
|
|
476
|
-
type
|
|
499
|
+
type OptionsFor<TData, TVariables extends OperationVariables, TOptions extends {
|
|
500
|
+
variables?: unknown;
|
|
501
|
+
}> = QueryOptions<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
502
|
+
variables?: Prettify<TVariables & {
|
|
503
|
+
[K in keyof TOptions["variables"]]: K extends keyof TVariables ? TVariables[K] : never;
|
|
504
|
+
}>;
|
|
505
|
+
} & (Exclude<keyof TOptions, keyof QueryOptions<any, any>> extends (infer InvalidOptionNames extends string) ? [
|
|
506
|
+
InvalidOptionNames
|
|
507
|
+
] extends [never] ? unknown : {
|
|
508
|
+
[K in InvalidOptionNames]: never;
|
|
509
|
+
} : never);
|
|
510
|
+
type ResultForOptions<TData, TVariables extends OperationVariables, TOptions extends Record<string, unknown> | Omit<QueryOptions<any, any>, "variables">> = LazyType<QueryResult<MaybeMasked<TData>, OptionWithFallback<TOptions, DefaultOptions, "errorPolicy"> & ErrorPolicy>>;
|
|
477
511
|
namespace Signatures {
|
|
478
512
|
interface Classic {
|
|
479
513
|
/**
|
|
@@ -515,9 +549,9 @@ export declare namespace ApolloClient {
|
|
|
515
549
|
* describe how this query should be treated e.g. whether it should hit the
|
|
516
550
|
* server at all or just resolve from the cache, etc.
|
|
517
551
|
*/
|
|
518
|
-
<TData, TVariables extends OperationVariables, TOptions extends ApolloClient.QueryOptions<NoInfer<TData>,
|
|
519
|
-
|
|
520
|
-
}
|
|
552
|
+
<TData, TVariables extends OperationVariables, TOptions extends Omit<ApolloClient.QueryOptions<NoInfer<TData>, any>, "variables"> & {
|
|
553
|
+
variables?: unknown;
|
|
554
|
+
}>(options: TOptions & ApolloClient.query.OptionsFor<TData, TVariables, TOptions> & {
|
|
521
555
|
query: TypedDocumentNode<TData, TVariables>;
|
|
522
556
|
}): Promise<ApolloClient.query.ResultForOptions<TData, TVariables, TOptions>>;
|
|
523
557
|
}
|
|
@@ -1262,13 +1262,49 @@ class ObservableQuery {
|
|
|
1262
1262
|
});
|
|
1263
1263
|
}
|
|
1264
1264
|
operator = (0, internal_1.filterMap)((notification) => {
|
|
1265
|
-
const { query,
|
|
1265
|
+
const { query, meta } = notification;
|
|
1266
1266
|
if (notification.source === "setResult") {
|
|
1267
|
-
return {
|
|
1267
|
+
return {
|
|
1268
|
+
query,
|
|
1269
|
+
variables: this.variables,
|
|
1270
|
+
result: notification.value,
|
|
1271
|
+
meta,
|
|
1272
|
+
};
|
|
1268
1273
|
}
|
|
1269
|
-
if (notification.kind === "C"
|
|
1274
|
+
if (notification.kind === "C") {
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
const resolvedVariables = "resolvedVariables" in notification ?
|
|
1278
|
+
notification.resolvedVariables
|
|
1279
|
+
: undefined;
|
|
1280
|
+
// Usually we prefer to drop notifications that don't match this query
|
|
1281
|
+
// but this breaks when used with `@export` queries that resolve variables
|
|
1282
|
+
// after the request is initiated. `notification.resolvedVariables` gives us
|
|
1283
|
+
// the variables the query actually resolved with during evaluation in
|
|
1284
|
+
// QueryManager (which is the variables value after `@export` variables have
|
|
1285
|
+
// been applied), but we need to update this query with those resolved
|
|
1286
|
+
// variables maybe in the middle of a request (updating is handled below).
|
|
1287
|
+
// When we update this.variables to the resolved variables, this causes
|
|
1288
|
+
// isEqualQuery(notification, this) to fail for future notifications since
|
|
1289
|
+
// the notification.variables holds the stale variables value. In this case,
|
|
1290
|
+
// we want to allow the notification through only if the current variables
|
|
1291
|
+
// value matches the resolved variables.
|
|
1292
|
+
//
|
|
1293
|
+
// Note: the check for matching resolved variables typically kicks in for
|
|
1294
|
+
// multi-emission fetches (such as defer, or cache-and-network, etc).
|
|
1295
|
+
if (notification.query !== this.query) {
|
|
1270
1296
|
return;
|
|
1271
1297
|
}
|
|
1298
|
+
if (!(0, equality_1.equal)(resolvedVariables, this.variables)) {
|
|
1299
|
+
if (!(0, equality_1.equal)(notification.variables, this.variables)) {
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
if (resolvedVariables) {
|
|
1303
|
+
this.options.variables = resolvedVariables;
|
|
1304
|
+
this.resubscribeCache();
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
const variables = this.variables;
|
|
1272
1308
|
let result;
|
|
1273
1309
|
const previous = this.subject.getValue();
|
|
1274
1310
|
if (notification.source === "cache") {
|
|
@@ -1289,7 +1325,9 @@ class ObservableQuery {
|
|
|
1289
1325
|
result =
|
|
1290
1326
|
notification.kind === "E" ?
|
|
1291
1327
|
{
|
|
1292
|
-
...(isEqualQuery(previous, notification)
|
|
1328
|
+
...((isEqualQuery(previous, notification) ||
|
|
1329
|
+
(resolvedVariables &&
|
|
1330
|
+
(0, equality_1.equal)(resolvedVariables, previous.variables))) ?
|
|
1293
1331
|
previous.result
|
|
1294
1332
|
: { data: undefined, dataState: "empty", partial: true }),
|
|
1295
1333
|
error: notification.error,
|