import { TypedDocumentNode } from '@graphql-typed-document-node/core'; import { DataService } from '@vendure/admin-ui/core'; import { DocumentNode } from 'graphql/index'; import { Observable } from 'rxjs'; /** * @description * A React hook which provides access to the results of a GraphQL query. * * @example * ```ts * import { useQuery } from '\@vendure/admin-ui/react'; * import { gql } from 'graphql-tag'; * * const GET_PRODUCT = gql` * query GetProduct($id: ID!) { * product(id: $id) { * id * name * description * } * }`; * * export const MyComponent = () => { * const { data, loading, error } = useQuery(GET_PRODUCT, { id: '1' }, { refetchOnChannelChange: true }); * * if (loading) return
Loading...
; * if (error) return
Error! { error }
; * return ( *
*

{data.product.name}

*

{data.product.description}

*
* ); * }; * ``` * * @docsCategory react-hooks */ export declare function useQuery = Record>(query: DocumentNode | TypedDocumentNode, variables?: V, options?: { refetchOnChannelChange: boolean; }): { readonly data: T | undefined; readonly loading: boolean; readonly error: string | undefined; readonly refetch: (variables?: V) => Promise; }; /** * @description * A React hook which allows you to execute a GraphQL query lazily. * * @example * ```ts * import { useLazyQuery } from '\@vendure/admin-ui/react'; * import { gql } from 'graphql-tag'; * * const GET_PRODUCT = gql` * query GetProduct($id: ID!) { * product(id: $id) { * id * name * description * } * }`; * type ProductResponse = { * product: { * name: string * description: string * } * } * * export const MyComponent = () => { * const [getProduct, { data, loading, error }] = useLazyQuery(GET_PRODUCT, { refetchOnChannelChange: true }); * * const handleClick = () => { * getProduct({ * id: '1', * }).then(result => { * // do something with the result * }); * }; * * if (loading) return
Loading...
; * if (error) return
Error! { error }
; * * return ( *
* * {data && ( *
*

{data.product.name}

*

{data.product.description}

*
)} *
* ); * }; * ``` * * @since 2.2.0 * @docsCategory react-hooks */ export declare function useLazyQuery = Record>(query: DocumentNode | TypedDocumentNode, options?: { refetchOnChannelChange: boolean; }): [(variables?: V) => Promise, { data: T | undefined; loading: boolean; error: string | undefined; }]; /** * @description * A React hook which allows you to execute a GraphQL mutation. * * @example * ```ts * import { useMutation } from '\@vendure/admin-ui/react'; * import { gql } from 'graphql-tag'; * * const UPDATE_PRODUCT = gql` * mutation UpdateProduct($input: UpdateProductInput!) { * updateProduct(input: $input) { * id * name * } * }`; * * export const MyComponent = () => { * const [updateProduct, { data, loading, error }] = useMutation(UPDATE_PRODUCT); * * const handleClick = () => { * updateProduct({ * input: { * id: '1', * name: 'New name', * }, * }).then(result => { * // do something with the result * }); * }; * * if (loading) return
Loading...
; * if (error) return
Error! { error }
; * * return ( *
* * {data &&
Product updated!
} *
* ); * }; * ``` * * @docsCategory react-hooks */ export declare function useMutation = Record>(mutation: DocumentNode | TypedDocumentNode): [(variables?: V) => Promise, { data: T | undefined; loading: boolean; error: string | undefined; }]; export declare function useDataService = Record>(operation: (dataService: DataService, variables?: V) => Observable): { data: T | undefined; loading: boolean; error: string | undefined; runQuery: (variables?: V) => Observable; };