@apollo/client 4.2.0-alpha.1 → 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 +209 -0
- package/__cjs/core/ApolloClient.cjs +25 -12
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +305 -146
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/defaultOptions.cjs +3 -0
- package/__cjs/core/defaultOptions.cjs.map +1 -0
- package/__cjs/core/defaultOptions.d.cts +90 -0
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +2 -1
- 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 +3 -3
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +1598 -765
- package/__cjs/react/hooks/useLazyQuery.cjs +3 -5
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +369 -115
- package/__cjs/react/hooks/useLoadableQuery.cjs +8 -4
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +507 -192
- 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 +5 -5
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +636 -276
- 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 +3 -3
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +799 -399
- package/__cjs/react/internal/cache/getSuspenseCache.cjs.map +1 -1
- package/__cjs/react/internal/cache/getSuspenseCache.d.cts +7 -0
- package/__cjs/utilities/internal/LazyType.cjs +3 -0
- package/__cjs/utilities/internal/LazyType.cjs.map +1 -0
- package/__cjs/utilities/internal/LazyType.d.cts +10 -0
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +3 -0
- package/__cjs/utilities/internal/types/OptionWithFallback.cjs +3 -0
- package/__cjs/utilities/internal/types/OptionWithFallback.cjs.map +1 -0
- package/__cjs/utilities/internal/types/OptionWithFallback.d.cts +5 -0
- package/__cjs/utilities/internal/types/SignatureStyle.cjs +3 -0
- package/__cjs/utilities/internal/types/SignatureStyle.cjs.map +1 -0
- package/__cjs/utilities/internal/types/SignatureStyle.d.cts +24 -0
- package/__cjs/version.cjs +1 -1
- package/core/ApolloClient.d.ts +305 -146
- package/core/ApolloClient.js +25 -12
- package/core/ApolloClient.js.map +1 -1
- package/core/QueryManager.js.map +1 -1
- package/core/defaultOptions.d.ts +90 -0
- package/core/defaultOptions.js +2 -0
- package/core/defaultOptions.js.map +1 -0
- package/core/index.d.ts +2 -1
- package/core/index.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 +1598 -765
- package/react/hooks/useBackgroundQuery.js +2 -2
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +369 -115
- package/react/hooks/useLazyQuery.js +2 -4
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +507 -192
- package/react/hooks/useLoadableQuery.js +7 -3
- 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 +636 -276
- package/react/hooks/useQuery.js +2 -2
- 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 +799 -399
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +1598 -765
- package/react/hooks-compiled/useBackgroundQuery.js +2 -2
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +369 -115
- package/react/hooks-compiled/useLazyQuery.js +2 -4
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +507 -192
- package/react/hooks-compiled/useLoadableQuery.js +2 -2
- 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 +636 -276
- package/react/hooks-compiled/useQuery.js +2 -2
- 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 +799 -399
- package/react/hooks-compiled/useSuspenseQuery.js +2 -2
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/getSuspenseCache.d.ts +7 -0
- package/react/internal/cache/getSuspenseCache.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/utilities/internal/LazyType.d.ts +10 -0
- package/utilities/internal/LazyType.js +2 -0
- package/utilities/internal/LazyType.js.map +1 -0
- package/utilities/internal/index.d.ts +3 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/types/OptionWithFallback.d.ts +5 -0
- package/utilities/internal/types/OptionWithFallback.js +2 -0
- package/utilities/internal/types/OptionWithFallback.js.map +1 -0
- package/utilities/internal/types/SignatureStyle.d.ts +24 -0
- package/utilities/internal/types/SignatureStyle.js +2 -0
- package/utilities/internal/types/SignatureStyle.js.map +1 -0
- package/version.js +1 -1
|
@@ -2,7 +2,7 @@ import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
|
|
2
2
|
import type { DocumentNode } from "graphql";
|
|
3
3
|
import type { ApolloClient, DataState, DefaultContext, ErrorLike, ErrorPolicy, GetDataState, InternalTypes, MaybeMasked, ObservableQuery, OperationVariables, RefetchWritePolicy, SubscribeToMoreFunction, UpdateQueryMapFn, WatchQueryFetchPolicy } from "@apollo/client";
|
|
4
4
|
import { NetworkStatus } from "@apollo/client";
|
|
5
|
-
import type { DocumentationTypes as UtilityDocumentationTypes, NoInfer, VariablesOption } from "@apollo/client/utilities/internal";
|
|
5
|
+
import type { DocumentationTypes as UtilityDocumentationTypes, NoInfer, OptionWithFallback, SignatureStyle, VariablesOption } from "@apollo/client/utilities/internal";
|
|
6
6
|
export declare namespace useLazyQuery {
|
|
7
7
|
import _self = useLazyQuery;
|
|
8
8
|
interface Options<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
|
|
@@ -279,11 +279,100 @@ export declare namespace useLazyQuery {
|
|
|
279
279
|
] : [options: useLazyQuery.ExecOptions<TVariables>]) => ObservableQuery.ResultPromise<ApolloClient.QueryResult<TData>>;
|
|
280
280
|
namespace DocumentationTypes {
|
|
281
281
|
namespace useLazyQuery {
|
|
282
|
-
export
|
|
282
|
+
export type { ResultTuple };
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
+
interface DefaultOptions extends ApolloClient.DefaultOptions.WatchQuery.Calculated {
|
|
286
|
+
}
|
|
287
|
+
type ResultForOptions<TData, TVariables extends OperationVariables, TOptions extends Record<string, never> | Options<TData, TVariables>> = ResultTuple<TData, TVariables, "complete" | "streaming" | "empty" | (OptionWithFallback<TOptions, DefaultOptions, "returnPartialData"> extends false ? never : "partial")>;
|
|
285
288
|
namespace DocumentationTypes {
|
|
289
|
+
interface useLazyQuery {
|
|
290
|
+
/**
|
|
291
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
292
|
+
*
|
|
293
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
*
|
|
297
|
+
* ```jsx
|
|
298
|
+
* import { gql } from "@apollo/client";
|
|
299
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
300
|
+
*
|
|
301
|
+
* const GET_GREETING = gql`
|
|
302
|
+
* query GetGreeting($language: String!) {
|
|
303
|
+
* greeting(language: $language) {
|
|
304
|
+
* message
|
|
305
|
+
* }
|
|
306
|
+
* }
|
|
307
|
+
* `;
|
|
308
|
+
*
|
|
309
|
+
* function Hello() {
|
|
310
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
311
|
+
* variables: { language: "english" },
|
|
312
|
+
* });
|
|
313
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
314
|
+
* if (!called) {
|
|
315
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
316
|
+
* }
|
|
317
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
318
|
+
* }
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
322
|
+
* @param options - Default options to control how the query is executed.
|
|
323
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
324
|
+
*/
|
|
325
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<TData, TVariables>): useLazyQuery.ResultTuple<TData, TVariables>;
|
|
326
|
+
}
|
|
327
|
+
interface useLazyQuery_Deprecated {
|
|
328
|
+
/**
|
|
329
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
330
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
331
|
+
*
|
|
332
|
+
*
|
|
333
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
334
|
+
*
|
|
335
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
*
|
|
339
|
+
* ```jsx
|
|
340
|
+
* import { gql } from "@apollo/client";
|
|
341
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
342
|
+
*
|
|
343
|
+
* const GET_GREETING = gql`
|
|
344
|
+
* query GetGreeting($language: String!) {
|
|
345
|
+
* greeting(language: $language) {
|
|
346
|
+
* message
|
|
347
|
+
* }
|
|
348
|
+
* }
|
|
349
|
+
* `;
|
|
350
|
+
*
|
|
351
|
+
* function Hello() {
|
|
352
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
353
|
+
* variables: { language: "english" },
|
|
354
|
+
* });
|
|
355
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
356
|
+
* if (!called) {
|
|
357
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
358
|
+
* }
|
|
359
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
360
|
+
* }
|
|
361
|
+
* ```
|
|
362
|
+
*
|
|
363
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
364
|
+
* @param options - Default options to control how the query is executed.
|
|
365
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
366
|
+
*/
|
|
367
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<TData, TVariables>): useLazyQuery.ResultTuple<TData, TVariables>;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
namespace Signatures {
|
|
286
371
|
/**
|
|
372
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
373
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
374
|
+
*
|
|
375
|
+
*
|
|
287
376
|
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
288
377
|
*
|
|
289
378
|
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
@@ -318,119 +407,284 @@ export declare namespace useLazyQuery {
|
|
|
318
407
|
* @param options - Default options to control how the query is executed.
|
|
319
408
|
* @returns A tuple in the form of `[execute, result]`
|
|
320
409
|
*/
|
|
321
|
-
|
|
410
|
+
interface Classic {
|
|
411
|
+
/**
|
|
412
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
413
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
414
|
+
*
|
|
415
|
+
*
|
|
416
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
417
|
+
*
|
|
418
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
*
|
|
422
|
+
* ```jsx
|
|
423
|
+
* import { gql } from "@apollo/client";
|
|
424
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
425
|
+
*
|
|
426
|
+
* const GET_GREETING = gql`
|
|
427
|
+
* query GetGreeting($language: String!) {
|
|
428
|
+
* greeting(language: $language) {
|
|
429
|
+
* message
|
|
430
|
+
* }
|
|
431
|
+
* }
|
|
432
|
+
* `;
|
|
433
|
+
*
|
|
434
|
+
* function Hello() {
|
|
435
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
436
|
+
* variables: { language: "english" },
|
|
437
|
+
* });
|
|
438
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
439
|
+
* if (!called) {
|
|
440
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
441
|
+
* }
|
|
442
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
443
|
+
* }
|
|
444
|
+
* ```
|
|
445
|
+
*
|
|
446
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
447
|
+
* @param options - Default options to control how the query is executed.
|
|
448
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
449
|
+
*/
|
|
450
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
451
|
+
returnPartialData: true;
|
|
452
|
+
}): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
453
|
+
/**
|
|
454
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
455
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
456
|
+
*
|
|
457
|
+
*
|
|
458
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
459
|
+
*
|
|
460
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
*
|
|
464
|
+
* ```jsx
|
|
465
|
+
* import { gql } from "@apollo/client";
|
|
466
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
467
|
+
*
|
|
468
|
+
* const GET_GREETING = gql`
|
|
469
|
+
* query GetGreeting($language: String!) {
|
|
470
|
+
* greeting(language: $language) {
|
|
471
|
+
* message
|
|
472
|
+
* }
|
|
473
|
+
* }
|
|
474
|
+
* `;
|
|
475
|
+
*
|
|
476
|
+
* function Hello() {
|
|
477
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
478
|
+
* variables: { language: "english" },
|
|
479
|
+
* });
|
|
480
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
481
|
+
* if (!called) {
|
|
482
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
483
|
+
* }
|
|
484
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
485
|
+
* }
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
489
|
+
* @param options - Default options to control how the query is executed.
|
|
490
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
491
|
+
*/
|
|
492
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
493
|
+
returnPartialData: boolean;
|
|
494
|
+
}): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
495
|
+
/**
|
|
496
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
497
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
498
|
+
*
|
|
499
|
+
*
|
|
500
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
501
|
+
*
|
|
502
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
*
|
|
506
|
+
* ```jsx
|
|
507
|
+
* import { gql } from "@apollo/client";
|
|
508
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
509
|
+
*
|
|
510
|
+
* const GET_GREETING = gql`
|
|
511
|
+
* query GetGreeting($language: String!) {
|
|
512
|
+
* greeting(language: $language) {
|
|
513
|
+
* message
|
|
514
|
+
* }
|
|
515
|
+
* }
|
|
516
|
+
* `;
|
|
517
|
+
*
|
|
518
|
+
* function Hello() {
|
|
519
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
520
|
+
* variables: { language: "english" },
|
|
521
|
+
* });
|
|
522
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
523
|
+
* if (!called) {
|
|
524
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
525
|
+
* }
|
|
526
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
527
|
+
* }
|
|
528
|
+
* ```
|
|
529
|
+
*
|
|
530
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
531
|
+
* @param options - Default options to control how the query is executed.
|
|
532
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
533
|
+
*/
|
|
534
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>>): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming">;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
538
|
+
*
|
|
539
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
*
|
|
543
|
+
* ```jsx
|
|
544
|
+
* import { gql } from "@apollo/client";
|
|
545
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
546
|
+
*
|
|
547
|
+
* const GET_GREETING = gql`
|
|
548
|
+
* query GetGreeting($language: String!) {
|
|
549
|
+
* greeting(language: $language) {
|
|
550
|
+
* message
|
|
551
|
+
* }
|
|
552
|
+
* }
|
|
553
|
+
* `;
|
|
554
|
+
*
|
|
555
|
+
* function Hello() {
|
|
556
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
557
|
+
* variables: { language: "english" },
|
|
558
|
+
* });
|
|
559
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
560
|
+
* if (!called) {
|
|
561
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
562
|
+
* }
|
|
563
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
566
|
+
*
|
|
567
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
568
|
+
* @param options - Default options to control how the query is executed.
|
|
569
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
570
|
+
*/
|
|
571
|
+
interface Modern {
|
|
572
|
+
/**
|
|
573
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
574
|
+
*
|
|
575
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
*
|
|
579
|
+
* ```jsx
|
|
580
|
+
* import { gql } from "@apollo/client";
|
|
581
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
582
|
+
*
|
|
583
|
+
* const GET_GREETING = gql`
|
|
584
|
+
* query GetGreeting($language: String!) {
|
|
585
|
+
* greeting(language: $language) {
|
|
586
|
+
* message
|
|
587
|
+
* }
|
|
588
|
+
* }
|
|
589
|
+
* `;
|
|
590
|
+
*
|
|
591
|
+
* function Hello() {
|
|
592
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
593
|
+
* variables: { language: "english" },
|
|
594
|
+
* });
|
|
595
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
596
|
+
* if (!called) {
|
|
597
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
598
|
+
* }
|
|
599
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
600
|
+
* }
|
|
601
|
+
* ```
|
|
602
|
+
*
|
|
603
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
604
|
+
* @param options - Default options to control how the query is executed.
|
|
605
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
606
|
+
*/
|
|
607
|
+
<TData, TVariables extends OperationVariables, TOptions extends never>(query: DocumentNode | TypedDocumentNode<TData, TVariables>): useLazyQuery.ResultForOptions<TData, TVariables, Record<string, never>>;
|
|
608
|
+
/**
|
|
609
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
610
|
+
*
|
|
611
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
*
|
|
615
|
+
* ```jsx
|
|
616
|
+
* import { gql } from "@apollo/client";
|
|
617
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
618
|
+
*
|
|
619
|
+
* const GET_GREETING = gql`
|
|
620
|
+
* query GetGreeting($language: String!) {
|
|
621
|
+
* greeting(language: $language) {
|
|
622
|
+
* message
|
|
623
|
+
* }
|
|
624
|
+
* }
|
|
625
|
+
* `;
|
|
626
|
+
*
|
|
627
|
+
* function Hello() {
|
|
628
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
629
|
+
* variables: { language: "english" },
|
|
630
|
+
* });
|
|
631
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
632
|
+
* if (!called) {
|
|
633
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
634
|
+
* }
|
|
635
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
636
|
+
* }
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
640
|
+
* @param options - Default options to control how the query is executed.
|
|
641
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
642
|
+
*/
|
|
643
|
+
<TData, TVariables extends OperationVariables, TOptions extends useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
644
|
+
variables?: {
|
|
645
|
+
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
|
|
646
|
+
};
|
|
647
|
+
}>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: TOptions): useLazyQuery.ResultForOptions<TData, TVariables, TOptions>;
|
|
648
|
+
}
|
|
649
|
+
type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
653
|
+
*
|
|
654
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
*
|
|
658
|
+
* ```jsx
|
|
659
|
+
* import { gql } from "@apollo/client";
|
|
660
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
661
|
+
*
|
|
662
|
+
* const GET_GREETING = gql`
|
|
663
|
+
* query GetGreeting($language: String!) {
|
|
664
|
+
* greeting(language: $language) {
|
|
665
|
+
* message
|
|
666
|
+
* }
|
|
667
|
+
* }
|
|
668
|
+
* `;
|
|
669
|
+
*
|
|
670
|
+
* function Hello() {
|
|
671
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
672
|
+
* variables: { language: "english" },
|
|
673
|
+
* });
|
|
674
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
675
|
+
* if (!called) {
|
|
676
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
677
|
+
* }
|
|
678
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
679
|
+
* }
|
|
680
|
+
* ```
|
|
681
|
+
*
|
|
682
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
683
|
+
* @param options - Default options to control how the query is executed.
|
|
684
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
685
|
+
*/
|
|
686
|
+
interface Signature extends Signatures.Evaluated {
|
|
322
687
|
}
|
|
323
688
|
}
|
|
324
|
-
|
|
325
|
-
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
326
|
-
*
|
|
327
|
-
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
328
|
-
*
|
|
329
|
-
* @example
|
|
330
|
-
*
|
|
331
|
-
* ```jsx
|
|
332
|
-
* import { gql } from "@apollo/client";
|
|
333
|
-
* import { useLazyQuery } from "@apollo/client/react";
|
|
334
|
-
*
|
|
335
|
-
* const GET_GREETING = gql`
|
|
336
|
-
* query GetGreeting($language: String!) {
|
|
337
|
-
* greeting(language: $language) {
|
|
338
|
-
* message
|
|
339
|
-
* }
|
|
340
|
-
* }
|
|
341
|
-
* `;
|
|
342
|
-
*
|
|
343
|
-
* function Hello() {
|
|
344
|
-
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
345
|
-
* variables: { language: "english" },
|
|
346
|
-
* });
|
|
347
|
-
* if (called && loading) return <p>Loading ...</p>;
|
|
348
|
-
* if (!called) {
|
|
349
|
-
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
350
|
-
* }
|
|
351
|
-
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
352
|
-
* }
|
|
353
|
-
* ```
|
|
354
|
-
*
|
|
355
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
356
|
-
* @param options - Default options to control how the query is executed.
|
|
357
|
-
* @returns A tuple in the form of `[execute, result]`
|
|
358
|
-
*/
|
|
359
|
-
export declare function useLazyQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
360
|
-
returnPartialData: true;
|
|
361
|
-
}): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
362
|
-
/**
|
|
363
|
-
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
364
|
-
*
|
|
365
|
-
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
366
|
-
*
|
|
367
|
-
* @example
|
|
368
|
-
*
|
|
369
|
-
* ```jsx
|
|
370
|
-
* import { gql } from "@apollo/client";
|
|
371
|
-
* import { useLazyQuery } from "@apollo/client/react";
|
|
372
|
-
*
|
|
373
|
-
* const GET_GREETING = gql`
|
|
374
|
-
* query GetGreeting($language: String!) {
|
|
375
|
-
* greeting(language: $language) {
|
|
376
|
-
* message
|
|
377
|
-
* }
|
|
378
|
-
* }
|
|
379
|
-
* `;
|
|
380
|
-
*
|
|
381
|
-
* function Hello() {
|
|
382
|
-
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
383
|
-
* variables: { language: "english" },
|
|
384
|
-
* });
|
|
385
|
-
* if (called && loading) return <p>Loading ...</p>;
|
|
386
|
-
* if (!called) {
|
|
387
|
-
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
388
|
-
* }
|
|
389
|
-
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
390
|
-
* }
|
|
391
|
-
* ```
|
|
392
|
-
*
|
|
393
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
394
|
-
* @param options - Default options to control how the query is executed.
|
|
395
|
-
* @returns A tuple in the form of `[execute, result]`
|
|
396
|
-
*/
|
|
397
|
-
export declare function useLazyQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
398
|
-
returnPartialData: boolean;
|
|
399
|
-
}): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
400
|
-
/**
|
|
401
|
-
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
402
|
-
*
|
|
403
|
-
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
404
|
-
*
|
|
405
|
-
* @example
|
|
406
|
-
*
|
|
407
|
-
* ```jsx
|
|
408
|
-
* import { gql } from "@apollo/client";
|
|
409
|
-
* import { useLazyQuery } from "@apollo/client/react";
|
|
410
|
-
*
|
|
411
|
-
* const GET_GREETING = gql`
|
|
412
|
-
* query GetGreeting($language: String!) {
|
|
413
|
-
* greeting(language: $language) {
|
|
414
|
-
* message
|
|
415
|
-
* }
|
|
416
|
-
* }
|
|
417
|
-
* `;
|
|
418
|
-
*
|
|
419
|
-
* function Hello() {
|
|
420
|
-
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
421
|
-
* variables: { language: "english" },
|
|
422
|
-
* });
|
|
423
|
-
* if (called && loading) return <p>Loading ...</p>;
|
|
424
|
-
* if (!called) {
|
|
425
|
-
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
426
|
-
* }
|
|
427
|
-
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
428
|
-
* }
|
|
429
|
-
* ```
|
|
430
|
-
*
|
|
431
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
432
|
-
* @param options - Default options to control how the query is executed.
|
|
433
|
-
* @returns A tuple in the form of `[execute, result]`
|
|
434
|
-
*/
|
|
435
|
-
export declare function useLazyQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>>): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming">;
|
|
689
|
+
export declare const useLazyQuery: useLazyQuery.Signature;
|
|
436
690
|
//# sourceMappingURL=useLazyQuery.d.ts.map
|
|
@@ -18,7 +18,7 @@ const EAGER_METHODS = [
|
|
|
18
18
|
"stopPolling",
|
|
19
19
|
"subscribeToMore",
|
|
20
20
|
];
|
|
21
|
-
export function useLazyQuery(query, options) {
|
|
21
|
+
export const useLazyQuery = function useLazyQuery(query, options) {
|
|
22
22
|
const client = useApolloClient(options?.client);
|
|
23
23
|
const previousDataRef = React.useRef(undefined);
|
|
24
24
|
const resultRef = React.useRef(undefined);
|
|
@@ -126,16 +126,14 @@ export function useLazyQuery(query, options) {
|
|
|
126
126
|
...eagerMethods_0,
|
|
127
127
|
...result_1,
|
|
128
128
|
client,
|
|
129
|
-
// eslint-disable-next-line react-hooks/refs
|
|
130
129
|
previousData: previousDataRef.current,
|
|
131
130
|
variables: observable.variables,
|
|
132
131
|
observable,
|
|
133
|
-
// eslint-disable-next-line react-hooks/refs
|
|
134
132
|
called: !!resultRef.current,
|
|
135
133
|
};
|
|
136
134
|
}, [client, observableResult, eagerMethods_0, observable]);
|
|
137
135
|
return [stableExecute, result_2];
|
|
138
|
-
}
|
|
136
|
+
};
|
|
139
137
|
const initialResult = maybeDeepFreeze({
|
|
140
138
|
data: undefined,
|
|
141
139
|
dataState: "empty",
|