Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute function of useLazyQuery should resolve FetchResult #174

Closed
tz5514 opened this issue Sep 12, 2019 · 6 comments
Closed

Execute function of useLazyQuery should resolve FetchResult #174

tz5514 opened this issue Sep 12, 2019 · 6 comments

Comments

@tz5514
Copy link

tz5514 commented Sep 12, 2019

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!

@jwld
Copy link

jwld commented Sep 17, 2019

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

@andresg747
Copy link

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.

@isrijanrana
Copy link

@tz5514 have you resolved this issue?

@tz5514
Copy link
Author

tz5514 commented Dec 12, 2019

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

@avanrielly
Copy link

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.

@hwillson
Copy link
Member

We think the useLazyQuery execute function should return a Promise that resolves to the FetchResult; we're tracking that work here: apollographql/apollo-client#7714

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants