import { ApolloCache } from "@apollo/client"; import { FetchPolicy, GraphQLTaggedNode, KeyType, KeyTypeData, OperationType } from "./types"; import { RefetchFn, PaginationFn } from "./storeObservation/compiledHooks"; /** * Executes a GraphQL query. * * This hook is called 'lazy' as it is used to fetch a GraphQL query _during_ render. This hook can trigger multiple * round trips, one for loading and one for resolving. * * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-lazy-load-query} * * @param query The query operation to perform. * @param variables Object containing the variable values to fetch the query. These variables need to match GraphQL * variables declared inside the query. * @param options Options passed on to the underlying implementation. * @param options.context The query context to pass along the apollo link chain. Should be avoided when possible as * it will not be compatible with Relay APIs. * @returns An object with either an error, the result data, or neither while loading. */ export declare function useLazyLoadQuery(query: GraphQLTaggedNode, variables: TQuery["variables"], options?: { fetchPolicy?: FetchPolicy; context?: TQuery["context"]; }): { error?: Error; data?: TQuery["response"]; }; /** * A first-class way for an individual component to express its direct data requirements using GraphQL. The fragment * should select all the fields that the component directly uses in its rendering or needs to pass to external * functions. It should *not* select data that its children need, unless those children are intended to remain their * pure React props as data inputs. * * For children that *do* have their own data requirements expressed using GraphQL, the fragment should ensure to * spread in the child's fragment. * * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-fragment} * * @note For migration purposes, this hook supports the notion that the fragment reference can be undefined. This is * to support cases where useFragment is used in a tree that is conditionally using fragments. * * @param fragmentInput The GraphQL fragment document created using the `graphql` tagged template function. * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's * fragment. * @returns The data corresponding to the field selections. */ export declare function useFragment(fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): KeyTypeData; export declare function useFragment(fragmentInput: GraphQLTaggedNode, fragmentRef: undefined): undefined; export declare function useFragment(fragmentInput: GraphQLTaggedNode, fragmentRef: TKey | undefined): KeyTypeData | undefined; /** * Equivalent to `useFragment`, but allows refetching of its subtree of the overall query. * * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-refetchable-fragment} * * @param fragmentInput The GraphQL fragment document created using the `graphql` tagged template function. * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's * fragment. * @returns The data corresponding to the field selections and a function to perform the refetch. */ export declare function useRefetchableFragment(fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): [data: KeyTypeData, refetch: RefetchFn]; /** * Equivalent to `useFragment`, but allows pagination of its subtree of the overall query. * * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-pagination-fragment} * * @param fragmentInput The GraphQL fragment document created using the `graphql` tagged template function. * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's * fragment. * @returns The data corresponding to the field selections and functions to deal with pagination. */ export declare function usePaginationFragment(fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): { data: KeyTypeData; loadNext: PaginationFn; loadPrevious: PaginationFn; hasNext: boolean; hasPrevious: boolean; isLoadingNext: boolean; isLoadingPrevious: boolean; refetch: RefetchFn; }; interface GraphQLSubscriptionConfig { subscription: GraphQLTaggedNode; variables: TSubscriptionPayload["variables"]; /** * Should be avoided when possible as it will not be compatible with Relay APIs. */ context?: TSubscriptionPayload["context"]; /** * Should response be nullable? */ onNext?: (response: TSubscriptionPayload["response"]) => void; onError?: (error: Error) => void; } /** * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-subscription} * * @param config */ export declare function useSubscription(config: GraphQLSubscriptionConfig): void; interface IMutationCommitterOptions { variables: TMutationPayload["variables"]; optimisticResponse?: Partial | null; onCompleted?: (response: TMutationPayload["response"]) => void; /** * This version yields the ApolloCache instance, instead of the RelayStore, * and usage of it will not be portable to Relay directly. However, it is a * necessary evil for migration purposes. */ updater?: (cache: ApolloCache, data: TMutationPayload["response"]) => void; /** * @deprecated Should be avoided when possible as it will not be compatible with Relay APIs. */ context?: TMutationPayload["context"]; } type MutationCommiter = (options: IMutationCommitterOptions) => Promise<{ errors?: Error[]; data?: TMutationPayload["response"]; }>; /** * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-mutation} * * @param mutation * @returns */ export declare function useMutation(mutation: GraphQLTaggedNode): [MutationCommiter, boolean]; export {}; //# sourceMappingURL=hooks.d.ts.map