Apollo-feature-requests: Execute function of useLazyQuery should resolve FetchResult

Created on 12 Sep 2019  路  5Comments  路  Source: apollographql/apollo-feature-requests

Hi, I just tried useLazyQuery for triggering query imperatively, and I found that the "execute function" would not resolve query result, but resolve with undefined.
This behavior make developer can't get query result by await the execute function.

For example, if I want to imperatively trigger query in a handleClick function and instantly use this result to do some calculating or logic, we can't.

In addition, since useMutation has a similar returning API with useLazyQuery and Mutate function will resolve fetch result, and same on refetch function of useQuery. I think useLazyQuery should has similar behavior. It should resolve with fetch result.

image

image

Thanks!

Most helpful comment

refetch on useQuery is only helpful if you want to display the new data. It is not helpful if you want to not call the query on page load, but you want to call it on a user method and do something with it immediately.

All 5 comments

Yes please 馃 Having to store the result in component state is a pita.

Totally agree with this.
useMutation API is predictable enough.
useLazyQuery has a very similar use case (speaking of imperative execution), and should have the same output type.

@tz5514 have you resolved this issue?

@srijanrana no, still use refetch of useQuery to replace it now.

refetch on useQuery is only helpful if you want to display the new data. It is not helpful if you want to not call the query on page load, but you want to call it on a user method and do something with it immediately.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FredyC picture FredyC  路  9Comments

noaelad picture noaelad  路  3Comments

Vincz picture Vincz  路  3Comments

haizz picture haizz  路  3Comments

renganatha10 picture renganatha10  路  6Comments