Add LazyQuery Hook#133
Conversation
There was a problem hiding this comment.
Hi @ZielonyBuszmen,
Thank you for doing this! The lack of bindings to useLazyQuery has been a real weak spot of this package.
There are a few things that don't work with the useLazyQuery hook (see the docs here).
The signature of useLazyQuery on the ts side is
function useLazyQuery<TData = any, TVariables = OperationVariables>(
query: DocumentNode,
options?: LazyQueryHookOptions<TData, TVariables>,
): [
(options?: QueryLazyOptions<TVariables>) => void,
QueryResult<TData, TVariables>
] {}
LazyQueryHookOptions<TData, TVariables>doesn't accept theskipparameter so neither shouldoptionshere.- The
QueryResult<TData, TVariables>returned byuseLazyQueryhas acalledfield. That field should be exposed in the bindings and used to set an appropriate value for the simple variant when it's not true (e.g.NotCalled) - The
fetchDatafunction on the ts side has this signature(options?: QueryLazyOptions<TVariables>) => voidwhere
export interface QueryLazyOptions<TVariables> {
variables?: TVariables;
context?: Context;
}
so beware that the options passed to useLazyQuery are not the same as those passed to the fetchData function.
Then there's a few things to do for consistency with the rest of reason-apollo-hooks.
- This hook should also accept
context. I don't think that it's particularly widely used, but the query and mutation hooks have it. useLazyQueryshould be available from the top-level module (same as howApolloHooks.rehas definitions foruseQuery,useMutationanduseSubscription)
Regarding using useMemo to wrap fetchData, I think the intention is that it is callable multiple times even with the same variables (akin to refetching) so I don't think useMemo is appropriate here (and the memo comparison [|variables|] will only check referential equality anyway).
|
Just took a look at |
I added LazyQuery Hook binding, because I cannot find it in this repository.