@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataState, DefaultContext, DocumentNode, ErrorLike, ErrorPolicy, GetDataState, InternalTypes, ObservableQuery, OperationVariables, RefetchWritePolicy, SubscribeToMoreFunction, TypedDocumentNode, UpdateQueryMapFn, WatchQueryFetchPolicy } from "@apollo/client";
|
|
1
|
+
import type { DataState, DefaultContext, DocumentNode, ErrorLike, ErrorPolicy, GetDataState, InternalTypes, ObservableQuery, OperationVariables, RefetchOn, RefetchWritePolicy, SubscribeToMoreFunction, TypedDocumentNode, UpdateQueryMapFn, WatchQueryFetchPolicy } from "@apollo/client";
|
|
2
2
|
import type { ApolloClient } from "@apollo/client";
|
|
3
3
|
import { NetworkStatus } from "@apollo/client";
|
|
4
4
|
import type { MaybeMasked } from "@apollo/client/masking";
|
|
@@ -111,6 +111,25 @@ export declare namespace useQuery {
|
|
|
111
111
|
* @docGroup 1. Operation options
|
|
112
112
|
*/
|
|
113
113
|
skip?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Determines whether events trigger refetches for the query. Provide an
|
|
116
|
+
* object mapping each refetch event to `true` (enable), `false` (disable)
|
|
117
|
+
* or a callback function that returns `true`/`false` to control individual
|
|
118
|
+
* events. Provide `false` to disable all automatic refetch events for this
|
|
119
|
+
* query. Provide `true` to enable all automatic refetch events for this query.
|
|
120
|
+
* Provide a callback function to perform additional logic to determine
|
|
121
|
+
* whether to enable or disable a refetch for a query.
|
|
122
|
+
*
|
|
123
|
+
* `@remarks`
|
|
124
|
+
* `refetchOn` inherits from `defaultOptions.watchQuery.refetchOn`. If
|
|
125
|
+
* `defaultOptions.watchQuery.refetchOn` is not set, all refetch events are
|
|
126
|
+
* enabled by default.
|
|
127
|
+
*
|
|
128
|
+
* This option only has an effect when the client is configured with a
|
|
129
|
+
* `refetchEventManager`.
|
|
130
|
+
* @docGroup 1. Operation options
|
|
131
|
+
*/
|
|
132
|
+
refetchOn?: RefetchOn.Option;
|
|
114
133
|
}
|
|
115
134
|
}
|
|
116
135
|
type Options<TData = unknown, TVariables extends OperationVariables = OperationVariables> = Base.Options<TData, TVariables> & VariablesOption<TVariables>;
|
|
@@ -237,94 +256,426 @@ export declare namespace useQuery {
|
|
|
237
256
|
}
|
|
238
257
|
}
|
|
239
258
|
namespace DocumentationTypes {
|
|
240
|
-
/**
|
|
241
|
-
* A hook for executing queries in an Apollo application.
|
|
242
|
-
*
|
|
243
|
-
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
244
|
-
*
|
|
245
|
-
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
246
|
-
*
|
|
247
|
-
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
*
|
|
251
|
-
* ```jsx
|
|
252
|
-
* import { gql } from "@apollo/client";
|
|
253
|
-
* import { useQuery } from "@apollo/client/react";
|
|
254
|
-
*
|
|
255
|
-
* const GET_GREETING = gql`
|
|
256
|
-
* query GetGreeting($language: String!) {
|
|
257
|
-
* greeting(language: $language) {
|
|
258
|
-
* message
|
|
259
|
-
* }
|
|
260
|
-
* }
|
|
261
|
-
* `;
|
|
262
|
-
*
|
|
263
|
-
* function Hello() {
|
|
264
|
-
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
265
|
-
* variables: { language: "english" },
|
|
266
|
-
* });
|
|
267
|
-
* if (loading) return <p>Loading ...</p>;
|
|
268
|
-
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
269
|
-
* }
|
|
270
|
-
* ```
|
|
271
|
-
*
|
|
272
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
273
|
-
* @param options - Options to control how the query is executed.
|
|
274
|
-
* @returns Query result object
|
|
275
|
-
*/
|
|
276
259
|
interface useQuery {
|
|
260
|
+
/**
|
|
261
|
+
* A hook for executing queries in an Apollo application.
|
|
262
|
+
*
|
|
263
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
264
|
+
*
|
|
265
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
266
|
+
*
|
|
267
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
*
|
|
271
|
+
* ```jsx
|
|
272
|
+
* import { gql } from "@apollo/client";
|
|
273
|
+
* import { useQuery } from "@apollo/client/react";
|
|
274
|
+
*
|
|
275
|
+
* const GET_GREETING = gql`
|
|
276
|
+
* query GetGreeting($language: String!) {
|
|
277
|
+
* greeting(language: $language) {
|
|
278
|
+
* message
|
|
279
|
+
* }
|
|
280
|
+
* }
|
|
281
|
+
* `;
|
|
282
|
+
*
|
|
283
|
+
* function Hello() {
|
|
284
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
285
|
+
* variables: { language: "english" },
|
|
286
|
+
* });
|
|
287
|
+
* if (loading) return <p>Loading ...</p>;
|
|
288
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
289
|
+
* }
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
293
|
+
* @param options - Options to control how the query is executed.
|
|
294
|
+
* @returns Query result object
|
|
295
|
+
*/
|
|
277
296
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<TData, TVariables>): useQuery.Result<TData, TVariables>;
|
|
278
297
|
}
|
|
279
|
-
/**
|
|
280
|
-
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
281
|
-
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
282
|
-
*/
|
|
283
298
|
interface useQuery_Deprecated {
|
|
299
|
+
/**
|
|
300
|
+
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
301
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
302
|
+
*
|
|
303
|
+
*
|
|
304
|
+
* A hook for executing queries in an Apollo application.
|
|
305
|
+
*
|
|
306
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
307
|
+
*
|
|
308
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
309
|
+
*
|
|
310
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
*
|
|
314
|
+
* ```jsx
|
|
315
|
+
* import { gql } from "@apollo/client";
|
|
316
|
+
* import { useQuery } from "@apollo/client/react";
|
|
317
|
+
*
|
|
318
|
+
* const GET_GREETING = gql`
|
|
319
|
+
* query GetGreeting($language: String!) {
|
|
320
|
+
* greeting(language: $language) {
|
|
321
|
+
* message
|
|
322
|
+
* }
|
|
323
|
+
* }
|
|
324
|
+
* `;
|
|
325
|
+
*
|
|
326
|
+
* function Hello() {
|
|
327
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
328
|
+
* variables: { language: "english" },
|
|
329
|
+
* });
|
|
330
|
+
* if (loading) return <p>Loading ...</p>;
|
|
331
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
332
|
+
* }
|
|
333
|
+
* ```
|
|
334
|
+
*
|
|
335
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
336
|
+
* @param options - Options to control how the query is executed.
|
|
337
|
+
* @returns Query result object
|
|
338
|
+
*/
|
|
284
339
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<TData, TVariables>): useQuery.Result<TData, TVariables>;
|
|
285
340
|
}
|
|
286
341
|
}
|
|
287
342
|
namespace Signatures {
|
|
288
343
|
/**
|
|
344
|
+
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
345
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
346
|
+
*
|
|
347
|
+
*
|
|
348
|
+
* A hook for executing queries in an Apollo application.
|
|
349
|
+
*
|
|
350
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
351
|
+
*
|
|
352
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
353
|
+
*
|
|
354
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
289
355
|
*
|
|
356
|
+
* @example
|
|
357
|
+
*
|
|
358
|
+
* ```jsx
|
|
359
|
+
* import { gql } from "@apollo/client";
|
|
360
|
+
* import { useQuery } from "@apollo/client/react";
|
|
361
|
+
*
|
|
362
|
+
* const GET_GREETING = gql`
|
|
363
|
+
* query GetGreeting($language: String!) {
|
|
364
|
+
* greeting(language: $language) {
|
|
365
|
+
* message
|
|
366
|
+
* }
|
|
367
|
+
* }
|
|
368
|
+
* `;
|
|
369
|
+
*
|
|
370
|
+
* function Hello() {
|
|
371
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
372
|
+
* variables: { language: "english" },
|
|
373
|
+
* });
|
|
374
|
+
* if (loading) return <p>Loading ...</p>;
|
|
375
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
376
|
+
* }
|
|
377
|
+
* ```
|
|
378
|
+
*
|
|
379
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
380
|
+
* @param options - Options to control how the query is executed.
|
|
381
|
+
* @returns Query result object
|
|
290
382
|
*/
|
|
291
383
|
interface Classic {
|
|
292
384
|
/**
|
|
385
|
+
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
386
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
387
|
+
*
|
|
388
|
+
*
|
|
389
|
+
* A hook for executing queries in an Apollo application.
|
|
390
|
+
*
|
|
391
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
392
|
+
*
|
|
393
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
293
394
|
*
|
|
395
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
*
|
|
399
|
+
* ```jsx
|
|
400
|
+
* import { gql } from "@apollo/client";
|
|
401
|
+
* import { useQuery } from "@apollo/client/react";
|
|
402
|
+
*
|
|
403
|
+
* const GET_GREETING = gql`
|
|
404
|
+
* query GetGreeting($language: String!) {
|
|
405
|
+
* greeting(language: $language) {
|
|
406
|
+
* message
|
|
407
|
+
* }
|
|
408
|
+
* }
|
|
409
|
+
* `;
|
|
410
|
+
*
|
|
411
|
+
* function Hello() {
|
|
412
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
413
|
+
* variables: { language: "english" },
|
|
414
|
+
* });
|
|
415
|
+
* if (loading) return <p>Loading ...</p>;
|
|
416
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
417
|
+
* }
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
421
|
+
* @param options - Options to control how the query is executed.
|
|
422
|
+
* @returns Query result object
|
|
294
423
|
*/
|
|
295
424
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
296
425
|
returnPartialData: true;
|
|
297
426
|
}): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
298
427
|
/**
|
|
428
|
+
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
429
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
430
|
+
*
|
|
431
|
+
*
|
|
432
|
+
* A hook for executing queries in an Apollo application.
|
|
433
|
+
*
|
|
434
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
435
|
+
*
|
|
436
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
299
437
|
*
|
|
438
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
*
|
|
442
|
+
* ```jsx
|
|
443
|
+
* import { gql } from "@apollo/client";
|
|
444
|
+
* import { useQuery } from "@apollo/client/react";
|
|
445
|
+
*
|
|
446
|
+
* const GET_GREETING = gql`
|
|
447
|
+
* query GetGreeting($language: String!) {
|
|
448
|
+
* greeting(language: $language) {
|
|
449
|
+
* message
|
|
450
|
+
* }
|
|
451
|
+
* }
|
|
452
|
+
* `;
|
|
453
|
+
*
|
|
454
|
+
* function Hello() {
|
|
455
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
456
|
+
* variables: { language: "english" },
|
|
457
|
+
* });
|
|
458
|
+
* if (loading) return <p>Loading ...</p>;
|
|
459
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
460
|
+
* }
|
|
461
|
+
* ```
|
|
462
|
+
*
|
|
463
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
464
|
+
* @param options - Options to control how the query is executed.
|
|
465
|
+
* @returns Query result object
|
|
300
466
|
*/
|
|
301
467
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken): useQuery.Result<TData, TVariables, "empty", Record<string, never>>;
|
|
302
468
|
/**
|
|
469
|
+
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
470
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
471
|
+
*
|
|
472
|
+
*
|
|
473
|
+
* A hook for executing queries in an Apollo application.
|
|
474
|
+
*
|
|
475
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
303
476
|
*
|
|
477
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
478
|
+
*
|
|
479
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
*
|
|
483
|
+
* ```jsx
|
|
484
|
+
* import { gql } from "@apollo/client";
|
|
485
|
+
* import { useQuery } from "@apollo/client/react";
|
|
486
|
+
*
|
|
487
|
+
* const GET_GREETING = gql`
|
|
488
|
+
* query GetGreeting($language: String!) {
|
|
489
|
+
* greeting(language: $language) {
|
|
490
|
+
* message
|
|
491
|
+
* }
|
|
492
|
+
* }
|
|
493
|
+
* `;
|
|
494
|
+
*
|
|
495
|
+
* function Hello() {
|
|
496
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
497
|
+
* variables: { language: "english" },
|
|
498
|
+
* });
|
|
499
|
+
* if (loading) return <p>Loading ...</p>;
|
|
500
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
501
|
+
* }
|
|
502
|
+
* ```
|
|
503
|
+
*
|
|
504
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
505
|
+
* @param options - Options to control how the query is executed.
|
|
506
|
+
* @returns Query result object
|
|
304
507
|
*/
|
|
305
508
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
306
509
|
returnPartialData: true;
|
|
307
510
|
})): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial", Partial<TVariables>>;
|
|
308
511
|
/**
|
|
512
|
+
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
513
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
514
|
+
*
|
|
515
|
+
*
|
|
516
|
+
* A hook for executing queries in an Apollo application.
|
|
517
|
+
*
|
|
518
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
309
519
|
*
|
|
520
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
521
|
+
*
|
|
522
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
*
|
|
526
|
+
* ```jsx
|
|
527
|
+
* import { gql } from "@apollo/client";
|
|
528
|
+
* import { useQuery } from "@apollo/client/react";
|
|
529
|
+
*
|
|
530
|
+
* const GET_GREETING = gql`
|
|
531
|
+
* query GetGreeting($language: String!) {
|
|
532
|
+
* greeting(language: $language) {
|
|
533
|
+
* message
|
|
534
|
+
* }
|
|
535
|
+
* }
|
|
536
|
+
* `;
|
|
537
|
+
*
|
|
538
|
+
* function Hello() {
|
|
539
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
540
|
+
* variables: { language: "english" },
|
|
541
|
+
* });
|
|
542
|
+
* if (loading) return <p>Loading ...</p>;
|
|
543
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
544
|
+
* }
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
548
|
+
* @param options - Options to control how the query is executed.
|
|
549
|
+
* @returns Query result object
|
|
310
550
|
*/
|
|
311
551
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
312
552
|
returnPartialData: boolean;
|
|
313
553
|
}): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
314
554
|
/**
|
|
555
|
+
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
556
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
557
|
+
*
|
|
558
|
+
*
|
|
559
|
+
* A hook for executing queries in an Apollo application.
|
|
315
560
|
*
|
|
561
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
562
|
+
*
|
|
563
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
564
|
+
*
|
|
565
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
*
|
|
569
|
+
* ```jsx
|
|
570
|
+
* import { gql } from "@apollo/client";
|
|
571
|
+
* import { useQuery } from "@apollo/client/react";
|
|
572
|
+
*
|
|
573
|
+
* const GET_GREETING = gql`
|
|
574
|
+
* query GetGreeting($language: String!) {
|
|
575
|
+
* greeting(language: $language) {
|
|
576
|
+
* message
|
|
577
|
+
* }
|
|
578
|
+
* }
|
|
579
|
+
* `;
|
|
580
|
+
*
|
|
581
|
+
* function Hello() {
|
|
582
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
583
|
+
* variables: { language: "english" },
|
|
584
|
+
* });
|
|
585
|
+
* if (loading) return <p>Loading ...</p>;
|
|
586
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
587
|
+
* }
|
|
588
|
+
* ```
|
|
589
|
+
*
|
|
590
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
591
|
+
* @param options - Options to control how the query is executed.
|
|
592
|
+
* @returns Query result object
|
|
316
593
|
*/
|
|
317
594
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
318
595
|
returnPartialData: boolean;
|
|
319
596
|
})): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial", Partial<TVariables>>;
|
|
320
597
|
/**
|
|
598
|
+
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
599
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
600
|
+
*
|
|
601
|
+
*
|
|
602
|
+
* A hook for executing queries in an Apollo application.
|
|
321
603
|
*
|
|
604
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
605
|
+
*
|
|
606
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
607
|
+
*
|
|
608
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
*
|
|
612
|
+
* ```jsx
|
|
613
|
+
* import { gql } from "@apollo/client";
|
|
614
|
+
* import { useQuery } from "@apollo/client/react";
|
|
615
|
+
*
|
|
616
|
+
* const GET_GREETING = gql`
|
|
617
|
+
* query GetGreeting($language: String!) {
|
|
618
|
+
* greeting(language: $language) {
|
|
619
|
+
* message
|
|
620
|
+
* }
|
|
621
|
+
* }
|
|
622
|
+
* `;
|
|
623
|
+
*
|
|
624
|
+
* function Hello() {
|
|
625
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
626
|
+
* variables: { language: "english" },
|
|
627
|
+
* });
|
|
628
|
+
* if (loading) return <p>Loading ...</p>;
|
|
629
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
630
|
+
* }
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
633
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
634
|
+
* @param options - Options to control how the query is executed.
|
|
635
|
+
* @returns Query result object
|
|
322
636
|
*/
|
|
323
637
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
324
638
|
options?: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>
|
|
325
639
|
] : [options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>]): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming">;
|
|
326
640
|
/**
|
|
641
|
+
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
642
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
643
|
+
*
|
|
327
644
|
*
|
|
645
|
+
* A hook for executing queries in an Apollo application.
|
|
646
|
+
*
|
|
647
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
648
|
+
*
|
|
649
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
650
|
+
*
|
|
651
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
*
|
|
655
|
+
* ```jsx
|
|
656
|
+
* import { gql } from "@apollo/client";
|
|
657
|
+
* import { useQuery } from "@apollo/client/react";
|
|
658
|
+
*
|
|
659
|
+
* const GET_GREETING = gql`
|
|
660
|
+
* query GetGreeting($language: String!) {
|
|
661
|
+
* greeting(language: $language) {
|
|
662
|
+
* message
|
|
663
|
+
* }
|
|
664
|
+
* }
|
|
665
|
+
* `;
|
|
666
|
+
*
|
|
667
|
+
* function Hello() {
|
|
668
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
669
|
+
* variables: { language: "english" },
|
|
670
|
+
* });
|
|
671
|
+
* if (loading) return <p>Loading ...</p>;
|
|
672
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
673
|
+
* }
|
|
674
|
+
* ```
|
|
675
|
+
*
|
|
676
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
677
|
+
* @param options - Options to control how the query is executed.
|
|
678
|
+
* @returns Query result object
|
|
328
679
|
*/
|
|
329
680
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
330
681
|
options?: SkipToken | useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>
|
|
@@ -334,19 +685,151 @@ export declare namespace useQuery {
|
|
|
334
685
|
ssrDisabledResult: ObservableQuery.Result<any>;
|
|
335
686
|
}
|
|
336
687
|
/**
|
|
688
|
+
* A hook for executing queries in an Apollo application.
|
|
689
|
+
*
|
|
690
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
337
691
|
*
|
|
692
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
693
|
+
*
|
|
694
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
695
|
+
*
|
|
696
|
+
* @example
|
|
697
|
+
*
|
|
698
|
+
* ```jsx
|
|
699
|
+
* import { gql } from "@apollo/client";
|
|
700
|
+
* import { useQuery } from "@apollo/client/react";
|
|
701
|
+
*
|
|
702
|
+
* const GET_GREETING = gql`
|
|
703
|
+
* query GetGreeting($language: String!) {
|
|
704
|
+
* greeting(language: $language) {
|
|
705
|
+
* message
|
|
706
|
+
* }
|
|
707
|
+
* }
|
|
708
|
+
* `;
|
|
709
|
+
*
|
|
710
|
+
* function Hello() {
|
|
711
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
712
|
+
* variables: { language: "english" },
|
|
713
|
+
* });
|
|
714
|
+
* if (loading) return <p>Loading ...</p>;
|
|
715
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
716
|
+
* }
|
|
717
|
+
* ```
|
|
718
|
+
*
|
|
719
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
720
|
+
* @param options - Options to control how the query is executed.
|
|
721
|
+
* @returns Query result object
|
|
338
722
|
*/
|
|
339
723
|
interface Modern {
|
|
340
724
|
/**
|
|
725
|
+
* A hook for executing queries in an Apollo application.
|
|
726
|
+
*
|
|
727
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
728
|
+
*
|
|
729
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
341
730
|
*
|
|
731
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
*
|
|
735
|
+
* ```jsx
|
|
736
|
+
* import { gql } from "@apollo/client";
|
|
737
|
+
* import { useQuery } from "@apollo/client/react";
|
|
738
|
+
*
|
|
739
|
+
* const GET_GREETING = gql`
|
|
740
|
+
* query GetGreeting($language: String!) {
|
|
741
|
+
* greeting(language: $language) {
|
|
742
|
+
* message
|
|
743
|
+
* }
|
|
744
|
+
* }
|
|
745
|
+
* `;
|
|
746
|
+
*
|
|
747
|
+
* function Hello() {
|
|
748
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
749
|
+
* variables: { language: "english" },
|
|
750
|
+
* });
|
|
751
|
+
* if (loading) return <p>Loading ...</p>;
|
|
752
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
753
|
+
* }
|
|
754
|
+
* ```
|
|
755
|
+
*
|
|
756
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
757
|
+
* @param options - Options to control how the query is executed.
|
|
758
|
+
* @returns Query result object
|
|
342
759
|
*/
|
|
343
760
|
<TData, TVariables extends OperationVariables, Options extends never>(query: {} extends TVariables ? DocumentNode | TypedDocumentNode<TData, TVariables> : never): useQuery.ResultForOptions<TData, TVariables, Record<string, never>>;
|
|
344
761
|
/**
|
|
762
|
+
* A hook for executing queries in an Apollo application.
|
|
763
|
+
*
|
|
764
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
765
|
+
*
|
|
766
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
767
|
+
*
|
|
768
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
345
771
|
*
|
|
772
|
+
* ```jsx
|
|
773
|
+
* import { gql } from "@apollo/client";
|
|
774
|
+
* import { useQuery } from "@apollo/client/react";
|
|
775
|
+
*
|
|
776
|
+
* const GET_GREETING = gql`
|
|
777
|
+
* query GetGreeting($language: String!) {
|
|
778
|
+
* greeting(language: $language) {
|
|
779
|
+
* message
|
|
780
|
+
* }
|
|
781
|
+
* }
|
|
782
|
+
* `;
|
|
783
|
+
*
|
|
784
|
+
* function Hello() {
|
|
785
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
786
|
+
* variables: { language: "english" },
|
|
787
|
+
* });
|
|
788
|
+
* if (loading) return <p>Loading ...</p>;
|
|
789
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
790
|
+
* }
|
|
791
|
+
* ```
|
|
792
|
+
*
|
|
793
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
794
|
+
* @param options - Options to control how the query is executed.
|
|
795
|
+
* @returns Query result object
|
|
346
796
|
*/
|
|
347
797
|
<TData, TVariables extends OperationVariables, TOptions extends SkipToken>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken): useQuery.Result<TData, TVariables, "empty", Record<string, never>>;
|
|
348
798
|
/**
|
|
799
|
+
* A hook for executing queries in an Apollo application.
|
|
800
|
+
*
|
|
801
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
802
|
+
*
|
|
803
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
804
|
+
*
|
|
805
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
806
|
+
*
|
|
807
|
+
* @example
|
|
808
|
+
*
|
|
809
|
+
* ```jsx
|
|
810
|
+
* import { gql } from "@apollo/client";
|
|
811
|
+
* import { useQuery } from "@apollo/client/react";
|
|
349
812
|
*
|
|
813
|
+
* const GET_GREETING = gql`
|
|
814
|
+
* query GetGreeting($language: String!) {
|
|
815
|
+
* greeting(language: $language) {
|
|
816
|
+
* message
|
|
817
|
+
* }
|
|
818
|
+
* }
|
|
819
|
+
* `;
|
|
820
|
+
*
|
|
821
|
+
* function Hello() {
|
|
822
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
823
|
+
* variables: { language: "english" },
|
|
824
|
+
* });
|
|
825
|
+
* if (loading) return <p>Loading ...</p>;
|
|
826
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
827
|
+
* }
|
|
828
|
+
* ```
|
|
829
|
+
*
|
|
830
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
831
|
+
* @param options - Options to control how the query is executed.
|
|
832
|
+
* @returns Query result object
|
|
350
833
|
*/
|
|
351
834
|
<TData, TVariables extends OperationVariables, TOptions extends useQuery.Options<TData, NoInfer<TVariables>> & VariablesOption<TVariables & {
|
|
352
835
|
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
|
|
@@ -356,7 +839,40 @@ export declare namespace useQuery {
|
|
|
356
839
|
options: TOptions
|
|
357
840
|
]): useQuery.ResultForOptions<TData, TVariables, TOptions>;
|
|
358
841
|
/**
|
|
842
|
+
* A hook for executing queries in an Apollo application.
|
|
843
|
+
*
|
|
844
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
845
|
+
*
|
|
846
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
847
|
+
*
|
|
848
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
*
|
|
852
|
+
* ```jsx
|
|
853
|
+
* import { gql } from "@apollo/client";
|
|
854
|
+
* import { useQuery } from "@apollo/client/react";
|
|
855
|
+
*
|
|
856
|
+
* const GET_GREETING = gql`
|
|
857
|
+
* query GetGreeting($language: String!) {
|
|
858
|
+
* greeting(language: $language) {
|
|
859
|
+
* message
|
|
860
|
+
* }
|
|
861
|
+
* }
|
|
862
|
+
* `;
|
|
359
863
|
*
|
|
864
|
+
* function Hello() {
|
|
865
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
866
|
+
* variables: { language: "english" },
|
|
867
|
+
* });
|
|
868
|
+
* if (loading) return <p>Loading ...</p>;
|
|
869
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
870
|
+
* }
|
|
871
|
+
* ```
|
|
872
|
+
*
|
|
873
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
874
|
+
* @param options - Options to control how the query is executed.
|
|
875
|
+
* @returns Query result object
|
|
360
876
|
*/
|
|
361
877
|
<TData, TVariables extends OperationVariables, TOptions extends useQuery.Options<TData, NoInfer<TVariables>> & VariablesOption<TVariables & {
|
|
362
878
|
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
|
|
@@ -370,7 +886,40 @@ export declare namespace useQuery {
|
|
|
370
886
|
type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
|
|
371
887
|
}
|
|
372
888
|
/**
|
|
889
|
+
* A hook for executing queries in an Apollo application.
|
|
890
|
+
*
|
|
891
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
892
|
+
*
|
|
893
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
894
|
+
*
|
|
895
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
896
|
+
*
|
|
897
|
+
* @example
|
|
898
|
+
*
|
|
899
|
+
* ```jsx
|
|
900
|
+
* import { gql } from "@apollo/client";
|
|
901
|
+
* import { useQuery } from "@apollo/client/react";
|
|
902
|
+
*
|
|
903
|
+
* const GET_GREETING = gql`
|
|
904
|
+
* query GetGreeting($language: String!) {
|
|
905
|
+
* greeting(language: $language) {
|
|
906
|
+
* message
|
|
907
|
+
* }
|
|
908
|
+
* }
|
|
909
|
+
* `;
|
|
910
|
+
*
|
|
911
|
+
* function Hello() {
|
|
912
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
913
|
+
* variables: { language: "english" },
|
|
914
|
+
* });
|
|
915
|
+
* if (loading) return <p>Loading ...</p>;
|
|
916
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
917
|
+
* }
|
|
918
|
+
* ```
|
|
373
919
|
*
|
|
920
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
921
|
+
* @param options - Options to control how the query is executed.
|
|
922
|
+
* @returns Query result object
|
|
374
923
|
*/
|
|
375
924
|
interface Signature extends Signatures.Evaluated {
|
|
376
925
|
}
|