@apollo/client 4.2.0-alpha.2 → 4.2.0-alpha.4
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 +240 -0
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- 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 +52 -20
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +159 -22
- package/__cjs/core/ObservableQuery.cjs +7 -7
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +20 -1
- package/__cjs/core/QueryManager.cjs +12 -12
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.cjs +134 -0
- package/__cjs/core/RefetchEventManager.cjs.map +1 -0
- package/__cjs/core/RefetchEventManager.d.cts +130 -0
- package/__cjs/core/index.cjs +7 -1
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +4 -1
- package/__cjs/core/refetchSources/onlineSource.cjs +10 -0
- package/__cjs/core/refetchSources/onlineSource.cjs.map +1 -0
- package/__cjs/core/refetchSources/onlineSource.d.cts +3 -0
- package/__cjs/core/refetchSources/windowFocusSource.cjs +13 -0
- package/__cjs/core/refetchSources/windowFocusSource.cjs.map +1 -0
- package/__cjs/core/refetchSources/windowFocusSource.d.cts +3 -0
- package/__cjs/core/types.d.cts +20 -0
- package/__cjs/invariantErrorCodes.cjs +69 -44
- package/__cjs/link/ws/index.cjs +9 -1
- package/__cjs/link/ws/index.cjs.map +1 -1
- package/__cjs/link/ws/index.d.cts +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +1486 -66
- package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +366 -40
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +512 -50
- package/__cjs/react/hooks/useMutation.cjs +5 -48
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +239 -130
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +590 -41
- package/__cjs/react/hooks/useSubscription.cjs +1 -1
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +2 -2
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +754 -46
- package/__cjs/react/internal/cache/QueryReference.cjs +1 -0
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -1
- package/__cjs/react/types/types.documentation.d.cts +19 -0
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.js +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/entityStore.js.map +1 -1
- 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 +159 -22
- package/core/ApolloClient.js +53 -21
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +20 -1
- package/core/ObservableQuery.js +7 -7
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.js +12 -12
- package/core/QueryManager.js.map +1 -1
- package/core/RefetchEventManager.d.ts +130 -0
- package/core/RefetchEventManager.js +126 -0
- package/core/RefetchEventManager.js.map +1 -0
- package/core/index.d.ts +4 -1
- package/core/index.js +3 -0
- package/core/index.js.map +1 -1
- package/core/refetchSources/onlineSource.d.ts +3 -0
- package/core/refetchSources/onlineSource.js +6 -0
- package/core/refetchSources/onlineSource.js.map +1 -0
- package/core/refetchSources/windowFocusSource.d.ts +3 -0
- package/core/refetchSources/windowFocusSource.js +9 -0
- package/core/refetchSources/windowFocusSource.js.map +1 -0
- package/core/types.d.ts +20 -0
- package/core/types.js.map +1 -1
- package/invariantErrorCodes.js +69 -44
- package/link/ws/index.d.ts +1 -1
- package/link/ws/index.js +9 -1
- package/link/ws/index.js.map +1 -1
- package/package.json +3 -7
- package/react/hooks/useBackgroundQuery.d.ts +1486 -66
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +366 -40
- package/react/hooks/useLazyQuery.js +1 -0
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +512 -50
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +239 -130
- package/react/hooks/useMutation.js +5 -48
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +590 -41
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +2 -2
- package/react/hooks/useSubscription.js +1 -1
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +754 -46
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +1486 -66
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +366 -40
- package/react/hooks-compiled/useLazyQuery.js +1 -0
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +512 -50
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +239 -130
- package/react/hooks-compiled/useMutation.js +4 -47
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +590 -41
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useSubscription.d.ts +2 -2
- package/react/hooks-compiled/useSubscription.js +1 -1
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +754 -46
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +1 -1
- package/react/internal/cache/QueryReference.js +1 -0
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +20 -1
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/types/types.documentation.d.ts +19 -0
- package/react/types/types.documentation.js.map +1 -1
- package/skills/apollo-client/SKILL.md +168 -0
- package/skills/apollo-client/references/caching.md +560 -0
- package/skills/apollo-client/references/error-handling.md +350 -0
- package/skills/apollo-client/references/fragments.md +804 -0
- package/skills/apollo-client/references/integration-client.md +336 -0
- package/skills/apollo-client/references/integration-nextjs.md +325 -0
- package/skills/apollo-client/references/integration-react-router.md +256 -0
- package/skills/apollo-client/references/integration-tanstack-start.md +378 -0
- package/skills/apollo-client/references/mutations.md +549 -0
- package/skills/apollo-client/references/queries.md +416 -0
- package/skills/apollo-client/references/state-management.md +428 -0
- package/skills/apollo-client/references/suspense-hooks.md +773 -0
- package/skills/apollo-client/references/troubleshooting.md +487 -0
- package/skills/apollo-client/references/typescript-codegen.md +133 -0
- package/version.js +1 -1
|
@@ -34,7 +34,7 @@ export function keyFieldsFnFromSpecifier(specifier) {
|
|
|
34
34
|
// context.readField for this extraction.
|
|
35
35
|
extracted = extractKeyPath(object, schemaKeyPath, extractKey);
|
|
36
36
|
}
|
|
37
|
-
invariant(extracted !== void 0,
|
|
37
|
+
invariant(extracted !== void 0, 107, schemaKeyPath.join("."), object);
|
|
38
38
|
return extracted;
|
|
39
39
|
}));
|
|
40
40
|
return `${context.typename}:${JSON.stringify(keyObject)}`;
|
|
@@ -220,7 +220,7 @@ export class Policies {
|
|
|
220
220
|
const rootId = "ROOT_" + which.toUpperCase();
|
|
221
221
|
const old = this.rootTypenamesById[rootId];
|
|
222
222
|
if (typename !== old) {
|
|
223
|
-
invariant(!old || old === which,
|
|
223
|
+
invariant(!old || old === which, 108, which);
|
|
224
224
|
// First, delete any old __typename associated with this rootId from
|
|
225
225
|
// rootIdsByTypename.
|
|
226
226
|
if (old)
|
|
@@ -363,7 +363,7 @@ export class Policies {
|
|
|
363
363
|
if (supertypeSet.has(supertype)) {
|
|
364
364
|
if (!typenameSupertypeSet.has(supertype)) {
|
|
365
365
|
if (checkingFuzzySubtypes) {
|
|
366
|
-
__DEV__ && invariant.warn(
|
|
366
|
+
__DEV__ && invariant.warn(109, typename, supertype);
|
|
367
367
|
}
|
|
368
368
|
// Record positive results for faster future lookup.
|
|
369
369
|
// Unfortunately, we cannot safely cache negative results,
|
|
@@ -615,7 +615,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
|
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
617
|
if (__DEV__ && options.from === void 0) {
|
|
618
|
-
__DEV__ && invariant.warn(
|
|
618
|
+
__DEV__ && invariant.warn(110, stringifyForDisplay(Array.from(readFieldArgs)));
|
|
619
619
|
}
|
|
620
620
|
if (void 0 === options.variables) {
|
|
621
621
|
options.variables = variables;
|
|
@@ -625,7 +625,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
|
|
|
625
625
|
function makeMergeObjectsFunction(store) {
|
|
626
626
|
return function mergeObjects(existing, incoming) {
|
|
627
627
|
if (isArray(existing) || isArray(incoming)) {
|
|
628
|
-
throw newInvariantError(
|
|
628
|
+
throw newInvariantError(111);
|
|
629
629
|
}
|
|
630
630
|
// These dynamic checks are necessary because the parameters of a
|
|
631
631
|
// custom merge function can easily have the any type, so the type
|
|
@@ -194,7 +194,7 @@ export class StoreReader {
|
|
|
194
194
|
else {
|
|
195
195
|
const fragment = getFragmentFromSelection(selection, context.lookupFragment);
|
|
196
196
|
if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
197
|
-
throw newInvariantError(
|
|
197
|
+
throw newInvariantError(112, selection.name.value);
|
|
198
198
|
}
|
|
199
199
|
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
200
200
|
fragment.selectionSet.selections.forEach(workSet.add, workSet);
|
|
@@ -277,7 +277,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
277
277
|
if (isNonNullObject(value)) {
|
|
278
278
|
invariant(
|
|
279
279
|
!isReference(value),
|
|
280
|
-
|
|
280
|
+
113,
|
|
281
281
|
getTypenameFromStoreObject(store, value),
|
|
282
282
|
field.name.value
|
|
283
283
|
);
|
|
@@ -68,7 +68,7 @@ export class StoreWriter {
|
|
|
68
68
|
path: [],
|
|
69
69
|
});
|
|
70
70
|
if (!isReference(ref)) {
|
|
71
|
-
throw newInvariantError(
|
|
71
|
+
throw newInvariantError(114, result);
|
|
72
72
|
}
|
|
73
73
|
// So far, the store has not been modified, so now it's time to process
|
|
74
74
|
// context.incomingById and merge those incoming fields into context.store.
|
|
@@ -230,7 +230,7 @@ export class StoreWriter {
|
|
|
230
230
|
// provide a default value, so its absence from the written data should
|
|
231
231
|
// not be cause for alarm.
|
|
232
232
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
233
|
-
invariant.error(
|
|
233
|
+
invariant.error(115, resultKeyNameFromField(field), result);
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
236
|
// Identify the result object, even if dataId was already provided,
|
|
@@ -378,7 +378,7 @@ export class StoreWriter {
|
|
|
378
378
|
else {
|
|
379
379
|
const fragment = getFragmentFromSelection(selection, context.lookupFragment);
|
|
380
380
|
if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
381
|
-
throw newInvariantError(
|
|
381
|
+
throw newInvariantError(116, selection.name.value);
|
|
382
382
|
}
|
|
383
383
|
if (fragment &&
|
|
384
384
|
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
@@ -550,7 +550,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
550
550
|
}
|
|
551
551
|
});
|
|
552
552
|
}
|
|
553
|
-
__DEV__ && invariant.warn(
|
|
553
|
+
__DEV__ && invariant.warn(117, fieldName, parentType, childTypenames.length ?
|
|
554
554
|
"either ensure all objects of type " +
|
|
555
555
|
childTypenames.join(" and ") +
|
|
556
556
|
" have an ID or a custom merge function, or "
|
package/core/ApolloClient.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ import type { LazyType, OptionWithFallback, SignatureStyle, VariablesOption, var
|
|
|
12
12
|
import { getApolloClientMemoryInternals } from "@apollo/client/utilities/internal";
|
|
13
13
|
import type { DeclareDefaultOptions, DefaultOptions } from "./defaultOptions.js";
|
|
14
14
|
import type { ObservableQuery } from "./ObservableQuery.js";
|
|
15
|
-
import type {
|
|
15
|
+
import type { RefetchEventManager } from "./RefetchEventManager.js";
|
|
16
|
+
import type { DefaultContext, ErrorLike, InternalRefetchQueriesInclude, InternalRefetchQueriesResult, MutationQueryReducersMap, MutationUpdaterFunction, NormalizedExecutionResult, OnQueryUpdated, OperationVariables, RefetchOn, RefetchQueriesInclude, RefetchQueriesPromiseResults, SubscriptionObservable, TypedDocumentNode } from "./types.js";
|
|
16
17
|
import type { ErrorPolicy, FetchPolicy, MutationFetchPolicy, NextFetchPolicyContext, RefetchWritePolicy, WatchQueryFetchPolicy } from "./watchQueryOptions.js";
|
|
17
18
|
/**
|
|
18
19
|
* @knipignore
|
|
@@ -28,6 +29,13 @@ export interface ReferenceToAvoidDroppingImportOnBuild {
|
|
|
28
29
|
}
|
|
29
30
|
export declare namespace ApolloClient {
|
|
30
31
|
export type { DeclareDefaultOptions, DefaultOptions };
|
|
32
|
+
export namespace DocumentationTypes {
|
|
33
|
+
interface DefaultOptions {
|
|
34
|
+
watchQuery?: Partial<ApolloClient.WatchQueryOptions<any, any>>;
|
|
35
|
+
query?: Partial<ApolloClient.QueryOptions<any, any>>;
|
|
36
|
+
mutate?: Partial<ApolloClient.MutateOptions<any, any, any>>;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
31
39
|
export interface Options extends InternalTypes.DefaultOptionsParentObject {
|
|
32
40
|
/**
|
|
33
41
|
* An `ApolloLink` instance to serve as Apollo Client's network layer. For more information, see [Advanced HTTP networking](https://www.apollographql.com/docs/react/networking/advanced-http-networking/).
|
|
@@ -99,6 +107,11 @@ export declare namespace ApolloClient {
|
|
|
99
107
|
* Do not pass in experiments that are not provided by Apollo.
|
|
100
108
|
*/
|
|
101
109
|
experiments?: ApolloClient.Experiment[];
|
|
110
|
+
/**
|
|
111
|
+
* The `RefetchEventManager` instance that manages automatic refetches for
|
|
112
|
+
* the client.
|
|
113
|
+
*/
|
|
114
|
+
refetchEventManager?: RefetchEventManager;
|
|
102
115
|
}
|
|
103
116
|
export interface DevtoolsOptions {
|
|
104
117
|
/**
|
|
@@ -216,24 +229,118 @@ export declare namespace ApolloClient {
|
|
|
216
229
|
*/
|
|
217
230
|
mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
|
218
231
|
} & VariablesOption<NoInfer<TVariables>>;
|
|
219
|
-
export
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
232
|
+
export namespace mutate {
|
|
233
|
+
interface DefaultOptions extends ApolloClient.DefaultOptions.Mutate.Calculated {
|
|
234
|
+
}
|
|
235
|
+
type ResultForOptions<TData, TVariables extends OperationVariables, TCache extends ApolloCache, TOptions extends Record<string, unknown> | MutateOptions<any, TVariables, TCache>> = LazyType<MutateResult<MaybeMasked<TData>, OptionWithFallback<TOptions, DefaultOptions, "errorPolicy"> & ErrorPolicy>>;
|
|
236
|
+
namespace Signatures {
|
|
237
|
+
interface Classic {
|
|
238
|
+
/**
|
|
239
|
+
* @deprecated Avoid manually specifying generics on `client.mutate`.
|
|
240
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your mutation results.
|
|
241
|
+
*
|
|
242
|
+
*
|
|
243
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
244
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
245
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
246
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
247
|
+
*
|
|
248
|
+
* It takes options as an object with the following keys and values:
|
|
249
|
+
*/
|
|
250
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache>(options: ApolloClient.MutateOptions<TData, TVariables, TCache>): Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
|
|
251
|
+
}
|
|
252
|
+
interface Modern {
|
|
253
|
+
/**
|
|
254
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
255
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
256
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
257
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
258
|
+
*
|
|
259
|
+
* It takes options as an object with the following keys and values:
|
|
260
|
+
*/
|
|
261
|
+
<TData, TVariables extends OperationVariables, TCache extends ApolloCache, TOptions extends ApolloClient.MutateOptions<NoInfer<TData>, NoInfer<TVariables>, TCache> & VariablesOption<TVariables & {
|
|
262
|
+
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
|
|
263
|
+
}>>(options: TOptions & {
|
|
264
|
+
mutation: TypedDocumentNode<TData, TVariables>;
|
|
265
|
+
}): Promise<ApolloClient.mutate.ResultForOptions<TData, TVariables, TCache, TOptions>>;
|
|
266
|
+
}
|
|
267
|
+
type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
|
|
268
|
+
}
|
|
226
269
|
/**
|
|
227
|
-
*
|
|
270
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
271
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
272
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
273
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
228
274
|
*
|
|
229
|
-
*
|
|
275
|
+
* It takes options as an object with the following keys and values:
|
|
230
276
|
*/
|
|
231
|
-
|
|
277
|
+
interface Signature extends Signatures.Evaluated {
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
export type MutateResultMap<TData = unknown> = {
|
|
281
|
+
none: {
|
|
282
|
+
/**
|
|
283
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
284
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
285
|
+
* but not `data` or a network error is returned.
|
|
286
|
+
*/
|
|
287
|
+
data: TData;
|
|
288
|
+
/**
|
|
289
|
+
* If the mutation produces one or more errors, this object contains either an array of `graphQLErrors` or a single `networkError`. Otherwise, this value is `undefined`.
|
|
290
|
+
*
|
|
291
|
+
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
292
|
+
*/
|
|
293
|
+
error?: never;
|
|
294
|
+
};
|
|
295
|
+
all: {
|
|
296
|
+
/**
|
|
297
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
298
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
299
|
+
* but not `data` or a network error is returned.
|
|
300
|
+
*/
|
|
301
|
+
data: TData | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* If the mutation produces one or more errors, this object contains either an array of `graphQLErrors` or a single `networkError`. Otherwise, this value is `undefined`.
|
|
304
|
+
*
|
|
305
|
+
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
306
|
+
*/
|
|
307
|
+
error?: ErrorLike;
|
|
308
|
+
};
|
|
309
|
+
ignore: {
|
|
310
|
+
/**
|
|
311
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
312
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
313
|
+
* but not `data` or a network error is returned.
|
|
314
|
+
*/
|
|
315
|
+
data: TData | undefined;
|
|
316
|
+
/**
|
|
317
|
+
* If the mutation produces one or more errors, this object contains either an array of `graphQLErrors` or a single `networkError`. Otherwise, this value is `undefined`.
|
|
318
|
+
*
|
|
319
|
+
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
320
|
+
*/
|
|
321
|
+
error?: never;
|
|
322
|
+
};
|
|
323
|
+
undefined: {
|
|
324
|
+
/**
|
|
325
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
326
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
327
|
+
* but not `data` or a network error is returned.
|
|
328
|
+
*/
|
|
329
|
+
data: TData | undefined;
|
|
330
|
+
/**
|
|
331
|
+
* If the mutation produces one or more errors, this object contains either an array of `graphQLErrors` or a single `networkError`. Otherwise, this value is `undefined`.
|
|
332
|
+
*
|
|
333
|
+
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
334
|
+
*/
|
|
335
|
+
error?: ErrorLike;
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
export type MutateResult<TData = unknown, TErrorPolicy extends ErrorPolicy | undefined = undefined> = MutateResultMap<TData>[`${TErrorPolicy}`] & {
|
|
232
339
|
/**
|
|
233
340
|
* Custom extensions returned from the GraphQL server
|
|
234
341
|
*/
|
|
235
342
|
extensions?: Record<string, unknown>;
|
|
236
|
-
}
|
|
343
|
+
};
|
|
237
344
|
/**
|
|
238
345
|
* Query options.
|
|
239
346
|
*/
|
|
@@ -271,7 +378,7 @@ export declare namespace ApolloClient {
|
|
|
271
378
|
*/
|
|
272
379
|
fetchPolicy?: FetchPolicy;
|
|
273
380
|
} & VariablesOption<NoInfer<TVariables>>;
|
|
274
|
-
export type QueryResultMap<TData = unknown
|
|
381
|
+
export type QueryResultMap<TData = unknown> = {
|
|
275
382
|
none: {
|
|
276
383
|
/**
|
|
277
384
|
* An object containing the result of your GraphQL query after it completes.
|
|
@@ -349,7 +456,7 @@ export declare namespace ApolloClient {
|
|
|
349
456
|
error?: ErrorLike;
|
|
350
457
|
};
|
|
351
458
|
};
|
|
352
|
-
export type QueryResult<TData = unknown, TErrorPolicy extends ErrorPolicy | undefined = undefined> = QueryResultMap<TData
|
|
459
|
+
export type QueryResult<TData = unknown, TErrorPolicy extends ErrorPolicy | undefined = undefined> = QueryResultMap<TData>[`${TErrorPolicy}`];
|
|
353
460
|
export namespace query {
|
|
354
461
|
interface DefaultOptions extends ApolloClient.DefaultOptions.Query.Calculated {
|
|
355
462
|
}
|
|
@@ -598,6 +705,25 @@ export declare namespace ApolloClient {
|
|
|
598
705
|
*/
|
|
599
706
|
query: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
|
600
707
|
/**
|
|
708
|
+
* Determines whether events trigger refetches for the query. Provide an
|
|
709
|
+
* object mapping each refetch event to `true` (enable), `false` (disable)
|
|
710
|
+
* or a callback function that returns `true`/`false` to control individual
|
|
711
|
+
* events. Provide `false` to disable all automatic refetch events for this
|
|
712
|
+
* query. Provide `true` to enable all automatic refetch events for this query.
|
|
713
|
+
* Provide a callback function to perform additional logic to determine
|
|
714
|
+
* whether to enable or disable a refetch for a query.
|
|
715
|
+
*
|
|
716
|
+
* `@remarks`
|
|
717
|
+
* `refetchOn` inherits from `defaultOptions.watchQuery.refetchOn`. If
|
|
718
|
+
* `defaultOptions.watchQuery.refetchOn` is not set, all refetch events are
|
|
719
|
+
* enabled by default.
|
|
720
|
+
*
|
|
721
|
+
* This option only has an effect when the client is configured with a
|
|
722
|
+
* `refetchEventManager`.
|
|
723
|
+
* @docGroup 1. Operation options
|
|
724
|
+
*/
|
|
725
|
+
refetchOn?: RefetchOn.Option;
|
|
726
|
+
/**
|
|
601
727
|
* @internal This API is meant for framework integrations only.
|
|
602
728
|
* Do not use for everyday use.
|
|
603
729
|
*
|
|
@@ -827,6 +953,15 @@ export declare namespace ApolloClient {
|
|
|
827
953
|
* server at all or just resolve from the cache, etc.
|
|
828
954
|
*/
|
|
829
955
|
function query<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.QueryOptions<TData, TVariables>): Promise<ApolloClient.QueryResult<MaybeMasked<TData>>>;
|
|
956
|
+
/**
|
|
957
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
958
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
959
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
960
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
961
|
+
*
|
|
962
|
+
* It takes options as an object with the following keys and values:
|
|
963
|
+
*/
|
|
964
|
+
function mutate<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache>(options: ApolloClient.MutateOptions<TData, TVariables, TCache>): Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
|
|
830
965
|
}
|
|
831
966
|
}
|
|
832
967
|
/**
|
|
@@ -855,6 +990,7 @@ export declare class ApolloClient {
|
|
|
855
990
|
queryDeduplication: boolean;
|
|
856
991
|
defaultOptions: ApolloClient.DefaultOptions;
|
|
857
992
|
readonly devtoolsConfig: ApolloClient.DevtoolsOptions;
|
|
993
|
+
readonly refetchEventManager: RefetchEventManager | undefined;
|
|
858
994
|
private queryManager;
|
|
859
995
|
private devToolsHookCb?;
|
|
860
996
|
private resetStoreCallbacks;
|
|
@@ -907,6 +1043,7 @@ export declare class ApolloClient {
|
|
|
907
1043
|
* - Unsubscribes all active `ObservableQuery` instances by emitting a `completed` event
|
|
908
1044
|
* - Rejects all currently running queries with "QueryManager stopped while query was in flight"
|
|
909
1045
|
* - Removes all queryRefs from the suspense cache
|
|
1046
|
+
* - Disconnects the `RefetchEventManager` if configured.
|
|
910
1047
|
*/
|
|
911
1048
|
stop(): void;
|
|
912
1049
|
/**
|
|
@@ -940,14 +1077,14 @@ export declare class ApolloClient {
|
|
|
940
1077
|
*/
|
|
941
1078
|
query: ApolloClient.query.Signature;
|
|
942
1079
|
/**
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
mutate
|
|
1080
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
1081
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
1082
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
1083
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
1084
|
+
*
|
|
1085
|
+
* It takes options as an object with the following keys and values:
|
|
1086
|
+
*/
|
|
1087
|
+
mutate: ApolloClient.mutate.Signature;
|
|
951
1088
|
/**
|
|
952
1089
|
* This subscribes to a graphql subscription according to the options specified and returns an
|
|
953
1090
|
* `Observable` which either emits received data or an error.
|
package/core/ApolloClient.js
CHANGED
|
@@ -4,7 +4,7 @@ import { NotImplementedHandler } from "@apollo/client/incremental";
|
|
|
4
4
|
import { execute } from "@apollo/client/link";
|
|
5
5
|
import { DocumentTransform } from "@apollo/client/utilities";
|
|
6
6
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
7
|
-
import { checkDocument, compact, getApolloClientMemoryInternals, mapObservableFragmentMemoized, mergeOptions, removeMaskedFragmentSpreads, } from "@apollo/client/utilities/internal";
|
|
7
|
+
import { checkDocument, compact, getApolloClientMemoryInternals, getOperationName, mapObservableFragmentMemoized, mergeOptions, removeMaskedFragmentSpreads, } from "@apollo/client/utilities/internal";
|
|
8
8
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
9
9
|
import { version } from "../version.js";
|
|
10
10
|
import { QueryManager } from "./QueryManager.js";
|
|
@@ -39,6 +39,7 @@ export class ApolloClient {
|
|
|
39
39
|
queryDeduplication;
|
|
40
40
|
defaultOptions;
|
|
41
41
|
devtoolsConfig;
|
|
42
|
+
refetchEventManager;
|
|
42
43
|
queryManager;
|
|
43
44
|
devToolsHookCb;
|
|
44
45
|
resetStoreCallbacks = [];
|
|
@@ -73,7 +74,7 @@ export class ApolloClient {
|
|
|
73
74
|
invariant(options.cache, 68);
|
|
74
75
|
invariant(options.link, 69);
|
|
75
76
|
}
|
|
76
|
-
const { cache, documentTransform, ssrMode = false, ssrForceFetchDelay = 0, queryDeduplication = true, defaultOptions, defaultContext, assumeImmutableResults = cache.assumeImmutableResults, localState, devtools, dataMasking, link, incrementalHandler = new NotImplementedHandler(), experiments = [], } = options;
|
|
77
|
+
const { cache, documentTransform, ssrMode = false, ssrForceFetchDelay = 0, queryDeduplication = true, defaultOptions, defaultContext, assumeImmutableResults = cache.assumeImmutableResults, localState, devtools, dataMasking, link, incrementalHandler = new NotImplementedHandler(), experiments = [], refetchEventManager, } = options;
|
|
77
78
|
this.link = link;
|
|
78
79
|
this.cache = cache;
|
|
79
80
|
this.queryDeduplication = queryDeduplication;
|
|
@@ -123,6 +124,8 @@ export class ApolloClient {
|
|
|
123
124
|
if (this.devtoolsConfig.enabled)
|
|
124
125
|
this.connectToDevTools();
|
|
125
126
|
experiments.forEach((experiment) => experiment.call(this, options));
|
|
127
|
+
this.refetchEventManager = refetchEventManager;
|
|
128
|
+
this.refetchEventManager?.connect(this);
|
|
126
129
|
}
|
|
127
130
|
connectToDevTools() {
|
|
128
131
|
if (typeof window === "undefined") {
|
|
@@ -193,9 +196,11 @@ export class ApolloClient {
|
|
|
193
196
|
* - Unsubscribes all active `ObservableQuery` instances by emitting a `completed` event
|
|
194
197
|
* - Rejects all currently running queries with "QueryManager stopped while query was in flight"
|
|
195
198
|
* - Removes all queryRefs from the suspense cache
|
|
199
|
+
* - Disconnects the `RefetchEventManager` if configured.
|
|
196
200
|
*/
|
|
197
201
|
stop() {
|
|
198
202
|
this.queryManager.stop();
|
|
203
|
+
this.refetchEventManager?.disconnect(this);
|
|
199
204
|
}
|
|
200
205
|
/**
|
|
201
206
|
* This watches the cache store of the query according to the options specified and
|
|
@@ -218,7 +223,34 @@ export class ApolloClient {
|
|
|
218
223
|
*/
|
|
219
224
|
watchQuery(options) {
|
|
220
225
|
if (this.defaultOptions.watchQuery) {
|
|
226
|
+
const defaultRefetchOn = this.defaultOptions.watchQuery.refetchOn;
|
|
227
|
+
const mergedRefetchOn = (options.refetchOn &&
|
|
228
|
+
typeof options.refetchOn === "object" &&
|
|
229
|
+
defaultRefetchOn &&
|
|
230
|
+
typeof defaultRefetchOn === "object") ?
|
|
231
|
+
{ ...defaultRefetchOn, ...options.refetchOn }
|
|
232
|
+
: undefined;
|
|
221
233
|
options = mergeOptions(this.defaultOptions.watchQuery, options);
|
|
234
|
+
if (mergedRefetchOn) {
|
|
235
|
+
options.refetchOn = mergedRefetchOn;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (__DEV__) {
|
|
239
|
+
const { refetchOn, query } = options;
|
|
240
|
+
const { refetchEventManager } = this;
|
|
241
|
+
if (refetchOn) {
|
|
242
|
+
const operationName = getOperationName(query, "(anonymous)");
|
|
243
|
+
if (!refetchEventManager) {
|
|
244
|
+
__DEV__ && invariant.warn(70, operationName);
|
|
245
|
+
}
|
|
246
|
+
else if (typeof refetchOn === "object") {
|
|
247
|
+
Object.keys(refetchOn).forEach((source) => {
|
|
248
|
+
if (!refetchEventManager.hasSource(source)) {
|
|
249
|
+
__DEV__ && invariant.warn(71, source, operationName);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
222
254
|
}
|
|
223
255
|
return this.queryManager.watchQuery(options);
|
|
224
256
|
}
|
|
@@ -236,37 +268,37 @@ export class ApolloClient {
|
|
|
236
268
|
options = mergeOptions(this.defaultOptions.query, options);
|
|
237
269
|
}
|
|
238
270
|
if (__DEV__) {
|
|
239
|
-
invariant(options.fetchPolicy !== "cache-and-network",
|
|
240
|
-
invariant(options.fetchPolicy !== "standby",
|
|
241
|
-
invariant(options.query,
|
|
242
|
-
invariant(options.query.kind === "Document",
|
|
243
|
-
invariant(!options.returnPartialData,
|
|
244
|
-
invariant(!options.pollInterval,
|
|
245
|
-
invariant(!options.notifyOnNetworkStatusChange,
|
|
271
|
+
invariant(options.fetchPolicy !== "cache-and-network", 72);
|
|
272
|
+
invariant(options.fetchPolicy !== "standby", 73);
|
|
273
|
+
invariant(options.query, 74);
|
|
274
|
+
invariant(options.query.kind === "Document", 75);
|
|
275
|
+
invariant(!options.returnPartialData, 76);
|
|
276
|
+
invariant(!options.pollInterval, 77);
|
|
277
|
+
invariant(!options.notifyOnNetworkStatusChange, 78);
|
|
246
278
|
}
|
|
247
279
|
return this.queryManager.query(options);
|
|
248
280
|
};
|
|
249
281
|
/**
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
mutate(options) {
|
|
282
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
283
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
284
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
285
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
286
|
+
*
|
|
287
|
+
* It takes options as an object with the following keys and values:
|
|
288
|
+
*/
|
|
289
|
+
mutate = (options) => {
|
|
258
290
|
const optionsWithDefaults = mergeOptions(compact({
|
|
259
291
|
fetchPolicy: "network-only",
|
|
260
292
|
errorPolicy: "none",
|
|
261
293
|
}, this.defaultOptions.mutate), options);
|
|
262
294
|
if (__DEV__) {
|
|
263
|
-
invariant(optionsWithDefaults.mutation,
|
|
295
|
+
invariant(optionsWithDefaults.mutation, 79);
|
|
264
296
|
invariant(optionsWithDefaults.fetchPolicy === "network-only" ||
|
|
265
|
-
optionsWithDefaults.fetchPolicy === "no-cache",
|
|
297
|
+
optionsWithDefaults.fetchPolicy === "no-cache", 80);
|
|
266
298
|
}
|
|
267
299
|
checkDocument(optionsWithDefaults.mutation, OperationTypeNode.MUTATION);
|
|
268
300
|
return this.queryManager.mutate(optionsWithDefaults);
|
|
269
|
-
}
|
|
301
|
+
};
|
|
270
302
|
/**
|
|
271
303
|
* This subscribes to a graphql subscription according to the options specified and returns an
|
|
272
304
|
* `Observable` which either emits received data or an error.
|
|
@@ -468,7 +500,7 @@ export class ApolloClient {
|
|
|
468
500
|
// result.queries and result.results instead, you shouldn't have to worry
|
|
469
501
|
// about preventing uncaught rejections for the Promise.all result.
|
|
470
502
|
result.catch((error) => {
|
|
471
|
-
__DEV__ && invariant.debug(
|
|
503
|
+
__DEV__ && invariant.debug(81, error);
|
|
472
504
|
});
|
|
473
505
|
return result;
|
|
474
506
|
}
|