@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.
Files changed (78) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/__cjs/core/ApolloClient.cjs +9 -9
  3. package/__cjs/core/ApolloClient.cjs.map +1 -1
  4. package/__cjs/core/ApolloClient.d.cts +131 -21
  5. package/__cjs/link/ws/index.cjs +9 -1
  6. package/__cjs/link/ws/index.cjs.map +1 -1
  7. package/__cjs/link/ws/index.d.cts +1 -1
  8. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  9. package/__cjs/react/hooks/useBackgroundQuery.d.cts +1466 -65
  10. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  11. package/__cjs/react/hooks/useLazyQuery.d.cts +346 -39
  12. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  13. package/__cjs/react/hooks/useLoadableQuery.d.cts +492 -49
  14. package/__cjs/react/hooks/useMutation.cjs +5 -48
  15. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  16. package/__cjs/react/hooks/useMutation.d.cts +239 -130
  17. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  18. package/__cjs/react/hooks/useQuery.d.cts +570 -40
  19. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  20. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  21. package/__cjs/react/hooks/useSubscription.d.cts +2 -2
  22. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  23. package/__cjs/react/hooks/useSuspenseQuery.d.cts +734 -45
  24. package/__cjs/version.cjs +1 -1
  25. package/core/ApolloClient.d.ts +131 -21
  26. package/core/ApolloClient.js +9 -9
  27. package/core/ApolloClient.js.map +1 -1
  28. package/link/ws/index.d.ts +1 -1
  29. package/link/ws/index.js +9 -1
  30. package/link/ws/index.js.map +1 -1
  31. package/package.json +3 -7
  32. package/react/hooks/useBackgroundQuery.d.ts +1466 -65
  33. package/react/hooks/useBackgroundQuery.js.map +1 -1
  34. package/react/hooks/useLazyQuery.d.ts +346 -39
  35. package/react/hooks/useLazyQuery.js.map +1 -1
  36. package/react/hooks/useLoadableQuery.d.ts +492 -49
  37. package/react/hooks/useLoadableQuery.js.map +1 -1
  38. package/react/hooks/useMutation.d.ts +239 -130
  39. package/react/hooks/useMutation.js +5 -48
  40. package/react/hooks/useMutation.js.map +1 -1
  41. package/react/hooks/useQuery.d.ts +570 -40
  42. package/react/hooks/useQuery.js.map +1 -1
  43. package/react/hooks/useSubscription.d.ts +2 -2
  44. package/react/hooks/useSubscription.js +1 -1
  45. package/react/hooks/useSubscription.js.map +1 -1
  46. package/react/hooks/useSuspenseQuery.d.ts +734 -45
  47. package/react/hooks/useSuspenseQuery.js.map +1 -1
  48. package/react/hooks-compiled/useBackgroundQuery.d.ts +1466 -65
  49. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  50. package/react/hooks-compiled/useLazyQuery.d.ts +346 -39
  51. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  52. package/react/hooks-compiled/useLoadableQuery.d.ts +492 -49
  53. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  54. package/react/hooks-compiled/useMutation.d.ts +239 -130
  55. package/react/hooks-compiled/useMutation.js +4 -47
  56. package/react/hooks-compiled/useMutation.js.map +1 -1
  57. package/react/hooks-compiled/useQuery.d.ts +570 -40
  58. package/react/hooks-compiled/useQuery.js.map +1 -1
  59. package/react/hooks-compiled/useSubscription.d.ts +2 -2
  60. package/react/hooks-compiled/useSubscription.js +1 -1
  61. package/react/hooks-compiled/useSubscription.js.map +1 -1
  62. package/react/hooks-compiled/useSuspenseQuery.d.ts +734 -45
  63. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  64. package/skills/apollo-client/SKILL.md +168 -0
  65. package/skills/apollo-client/references/caching.md +560 -0
  66. package/skills/apollo-client/references/error-handling.md +350 -0
  67. package/skills/apollo-client/references/fragments.md +804 -0
  68. package/skills/apollo-client/references/integration-client.md +336 -0
  69. package/skills/apollo-client/references/integration-nextjs.md +325 -0
  70. package/skills/apollo-client/references/integration-react-router.md +256 -0
  71. package/skills/apollo-client/references/integration-tanstack-start.md +378 -0
  72. package/skills/apollo-client/references/mutations.md +549 -0
  73. package/skills/apollo-client/references/queries.md +416 -0
  74. package/skills/apollo-client/references/state-management.md +428 -0
  75. package/skills/apollo-client/references/suspense-hooks.md +773 -0
  76. package/skills/apollo-client/references/troubleshooting.md +487 -0
  77. package/skills/apollo-client/references/typescript-codegen.md +133 -0
  78. package/version.js +1 -1
package/__cjs/version.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.build = exports.version = void 0;
4
- exports.version = "4.2.0-alpha.2";
4
+ exports.version = "4.2.0-alpha.3";
5
5
  exports.build = "cjs";
6
6
  //# sourceMappingURL=version.cjs.map
@@ -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 interface MutateResult<TData = unknown> {
220
- /**
221
- * The data returned from your mutation. Can be `undefined` if the `errorPolicy`
222
- * is `all` or `ignore` and the server returns a GraphQL response with `errors`
223
- * but not `data` or a network error is returned.
224
- */
225
- data: TData | undefined;
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
- * 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`.
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
- * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
269
+ * It takes options as an object with the following keys and values:
230
270
  */
231
- error?: ErrorLike;
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, TErrorPolicy extends ErrorPolicy | undefined = undefined> = {
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, TErrorPolicy>[`${TErrorPolicy}`];
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
- * This resolves a single mutation according to the options specified and returns a
944
- * Promise which is either resolved with the resulting data or rejected with an
945
- * error. In some cases both `data` and `errors` might be undefined, for example
946
- * when `errorPolicy` is set to `'ignore'`.
947
- *
948
- * It takes options as an object with the following keys and values:
949
- */
950
- mutate<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache>(options: ApolloClient.MutateOptions<TData, TVariables, TCache>): Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
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.
@@ -247,14 +247,14 @@ export class ApolloClient {
247
247
  return this.queryManager.query(options);
248
248
  };
249
249
  /**
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) {
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.