@apollo/client 4.2.0-alpha.2 → 4.2.0-alpha.3
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 +61 -0
- package/__cjs/core/ApolloClient.cjs +9 -9
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +131 -21
- 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 +1466 -65
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +346 -39
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +492 -49
- 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 +570 -40
- 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 +734 -45
- package/__cjs/version.cjs +1 -1
- package/core/ApolloClient.d.ts +131 -21
- package/core/ApolloClient.js +9 -9
- package/core/ApolloClient.js.map +1 -1
- 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 +1466 -65
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +346 -39
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +492 -49
- 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 +570 -40
- 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 +734 -45
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +1466 -65
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +346 -39
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +492 -49
- 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 +570 -40
- 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 +734 -45
- package/react/hooks-compiled/useSuspenseQuery.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
package/__cjs/version.cjs
CHANGED
package/core/ApolloClient.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ export interface ReferenceToAvoidDroppingImportOnBuild {
|
|
|
28
28
|
}
|
|
29
29
|
export declare namespace ApolloClient {
|
|
30
30
|
export type { DeclareDefaultOptions, DefaultOptions };
|
|
31
|
+
export namespace DocumentationTypes {
|
|
32
|
+
interface DefaultOptions {
|
|
33
|
+
watchQuery?: Partial<ApolloClient.WatchQueryOptions<any, any>>;
|
|
34
|
+
query?: Partial<ApolloClient.QueryOptions<any, any>>;
|
|
35
|
+
mutate?: Partial<ApolloClient.MutateOptions<any, any, any>>;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
31
38
|
export interface Options extends InternalTypes.DefaultOptionsParentObject {
|
|
32
39
|
/**
|
|
33
40
|
* 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/).
|
|
@@ -216,24 +223,118 @@ export declare namespace ApolloClient {
|
|
|
216
223
|
*/
|
|
217
224
|
mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
|
218
225
|
} & VariablesOption<NoInfer<TVariables>>;
|
|
219
|
-
export
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
+
export namespace mutate {
|
|
227
|
+
interface DefaultOptions extends ApolloClient.DefaultOptions.Mutate.Calculated {
|
|
228
|
+
}
|
|
229
|
+
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>>;
|
|
230
|
+
namespace Signatures {
|
|
231
|
+
interface Classic {
|
|
232
|
+
/**
|
|
233
|
+
* @deprecated Avoid manually specifying generics on `client.mutate`.
|
|
234
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your mutation results.
|
|
235
|
+
*
|
|
236
|
+
*
|
|
237
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
238
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
239
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
240
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
241
|
+
*
|
|
242
|
+
* It takes options as an object with the following keys and values:
|
|
243
|
+
*/
|
|
244
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache>(options: ApolloClient.MutateOptions<TData, TVariables, TCache>): Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
|
|
245
|
+
}
|
|
246
|
+
interface Modern {
|
|
247
|
+
/**
|
|
248
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
249
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
250
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
251
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
252
|
+
*
|
|
253
|
+
* It takes options as an object with the following keys and values:
|
|
254
|
+
*/
|
|
255
|
+
<TData, TVariables extends OperationVariables, TCache extends ApolloCache, TOptions extends ApolloClient.MutateOptions<NoInfer<TData>, NoInfer<TVariables>, TCache> & VariablesOption<TVariables & {
|
|
256
|
+
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
|
|
257
|
+
}>>(options: TOptions & {
|
|
258
|
+
mutation: TypedDocumentNode<TData, TVariables>;
|
|
259
|
+
}): Promise<ApolloClient.mutate.ResultForOptions<TData, TVariables, TCache, TOptions>>;
|
|
260
|
+
}
|
|
261
|
+
type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
|
|
262
|
+
}
|
|
226
263
|
/**
|
|
227
|
-
*
|
|
264
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
265
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
266
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
267
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
228
268
|
*
|
|
229
|
-
*
|
|
269
|
+
* It takes options as an object with the following keys and values:
|
|
230
270
|
*/
|
|
231
|
-
|
|
271
|
+
interface Signature extends Signatures.Evaluated {
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
export type MutateResultMap<TData = unknown> = {
|
|
275
|
+
none: {
|
|
276
|
+
/**
|
|
277
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
278
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
279
|
+
* but not `data` or a network error is returned.
|
|
280
|
+
*/
|
|
281
|
+
data: TData;
|
|
282
|
+
/**
|
|
283
|
+
* 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`.
|
|
284
|
+
*
|
|
285
|
+
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
286
|
+
*/
|
|
287
|
+
error?: never;
|
|
288
|
+
};
|
|
289
|
+
all: {
|
|
290
|
+
/**
|
|
291
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
292
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
293
|
+
* but not `data` or a network error is returned.
|
|
294
|
+
*/
|
|
295
|
+
data: TData | undefined;
|
|
296
|
+
/**
|
|
297
|
+
* 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`.
|
|
298
|
+
*
|
|
299
|
+
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
300
|
+
*/
|
|
301
|
+
error?: ErrorLike;
|
|
302
|
+
};
|
|
303
|
+
ignore: {
|
|
304
|
+
/**
|
|
305
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
306
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
307
|
+
* but not `data` or a network error is returned.
|
|
308
|
+
*/
|
|
309
|
+
data: TData | undefined;
|
|
310
|
+
/**
|
|
311
|
+
* 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`.
|
|
312
|
+
*
|
|
313
|
+
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
314
|
+
*/
|
|
315
|
+
error?: never;
|
|
316
|
+
};
|
|
317
|
+
undefined: {
|
|
318
|
+
/**
|
|
319
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
320
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
321
|
+
* but not `data` or a network error is returned.
|
|
322
|
+
*/
|
|
323
|
+
data: TData | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* 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`.
|
|
326
|
+
*
|
|
327
|
+
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
328
|
+
*/
|
|
329
|
+
error?: ErrorLike;
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
export type MutateResult<TData = unknown, TErrorPolicy extends ErrorPolicy | undefined = undefined> = MutateResultMap<TData>[`${TErrorPolicy}`] & {
|
|
232
333
|
/**
|
|
233
334
|
* Custom extensions returned from the GraphQL server
|
|
234
335
|
*/
|
|
235
336
|
extensions?: Record<string, unknown>;
|
|
236
|
-
}
|
|
337
|
+
};
|
|
237
338
|
/**
|
|
238
339
|
* Query options.
|
|
239
340
|
*/
|
|
@@ -271,7 +372,7 @@ export declare namespace ApolloClient {
|
|
|
271
372
|
*/
|
|
272
373
|
fetchPolicy?: FetchPolicy;
|
|
273
374
|
} & VariablesOption<NoInfer<TVariables>>;
|
|
274
|
-
export type QueryResultMap<TData = unknown
|
|
375
|
+
export type QueryResultMap<TData = unknown> = {
|
|
275
376
|
none: {
|
|
276
377
|
/**
|
|
277
378
|
* An object containing the result of your GraphQL query after it completes.
|
|
@@ -349,7 +450,7 @@ export declare namespace ApolloClient {
|
|
|
349
450
|
error?: ErrorLike;
|
|
350
451
|
};
|
|
351
452
|
};
|
|
352
|
-
export type QueryResult<TData = unknown, TErrorPolicy extends ErrorPolicy | undefined = undefined> = QueryResultMap<TData
|
|
453
|
+
export type QueryResult<TData = unknown, TErrorPolicy extends ErrorPolicy | undefined = undefined> = QueryResultMap<TData>[`${TErrorPolicy}`];
|
|
353
454
|
export namespace query {
|
|
354
455
|
interface DefaultOptions extends ApolloClient.DefaultOptions.Query.Calculated {
|
|
355
456
|
}
|
|
@@ -827,6 +928,15 @@ export declare namespace ApolloClient {
|
|
|
827
928
|
* server at all or just resolve from the cache, etc.
|
|
828
929
|
*/
|
|
829
930
|
function query<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.QueryOptions<TData, TVariables>): Promise<ApolloClient.QueryResult<MaybeMasked<TData>>>;
|
|
931
|
+
/**
|
|
932
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
933
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
934
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
935
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
936
|
+
*
|
|
937
|
+
* It takes options as an object with the following keys and values:
|
|
938
|
+
*/
|
|
939
|
+
function mutate<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache>(options: ApolloClient.MutateOptions<TData, TVariables, TCache>): Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
|
|
830
940
|
}
|
|
831
941
|
}
|
|
832
942
|
/**
|
|
@@ -940,14 +1050,14 @@ export declare class ApolloClient {
|
|
|
940
1050
|
*/
|
|
941
1051
|
query: ApolloClient.query.Signature;
|
|
942
1052
|
/**
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
mutate
|
|
1053
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
1054
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
1055
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
1056
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
1057
|
+
*
|
|
1058
|
+
* It takes options as an object with the following keys and values:
|
|
1059
|
+
*/
|
|
1060
|
+
mutate: ApolloClient.mutate.Signature;
|
|
951
1061
|
/**
|
|
952
1062
|
* This subscribes to a graphql subscription according to the options specified and returns an
|
|
953
1063
|
* `Observable` which either emits received data or an error.
|
package/core/ApolloClient.js
CHANGED
|
@@ -247,14 +247,14 @@ export class ApolloClient {
|
|
|
247
247
|
return this.queryManager.query(options);
|
|
248
248
|
};
|
|
249
249
|
/**
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
mutate(options) {
|
|
250
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
251
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
252
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
253
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
254
|
+
*
|
|
255
|
+
* It takes options as an object with the following keys and values:
|
|
256
|
+
*/
|
|
257
|
+
mutate = (options) => {
|
|
258
258
|
const optionsWithDefaults = mergeOptions(compact({
|
|
259
259
|
fetchPolicy: "network-only",
|
|
260
260
|
errorPolicy: "none",
|
|
@@ -266,7 +266,7 @@ export class ApolloClient {
|
|
|
266
266
|
}
|
|
267
267
|
checkDocument(optionsWithDefaults.mutation, OperationTypeNode.MUTATION);
|
|
268
268
|
return this.queryManager.mutate(optionsWithDefaults);
|
|
269
|
-
}
|
|
269
|
+
};
|
|
270
270
|
/**
|
|
271
271
|
* This subscribes to a graphql subscription according to the options specified and returns an
|
|
272
272
|
* `Observable` which either emits received data or an error.
|