IssueRaiser

useLazyQuery execution function should return a promise

People don't know if they should use a query or a mutation to login an user when that login performs no side-effect (ie, just query for an auth token). https://stackoverflow.com/questions/50189364/shouldnt-the-login-be-a-query-in-graphql But Apollo users tend to currently use mutations because they want the operation to execute only after user press a submit button. Recently a new useLazyQuery was added (by @FredyC I think?), and it could be useful to solve this problem: keep a query, but actually execute it after user press a button. Unlike mutations, it does not return a promise when executed. I suggest the following should be possible: ![image](https://user-images.githubusercontent.com/749374/64979571-47b2e800-d8b8-11e9-9991-f082ee4879f7.png) **edit**: actually the screenshot is wrong but you probably understand the point of returning a promise instead of void here (at least in TS typings) Note other apis do return a promise when called (see "refetch" for example). I think useLazyQuery should follow the exact same convention and not return void.

Posted by slorber on Sep 16, 2019, 5:33 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

github (Other)

useLazyQuery execution function should return a promise

slorberSep 16, 2019, 5:33 PM

People don't know if they should use a query or a mutation to login an user when that login performs no side-effect (ie, just query for an auth token). https://stackoverflow.com/questions/50189364/shouldnt-the-login-be-a-query-in-graphql But Apollo users tend to currently use mutations because they want the operation to execute only after user press a submit button. Recently a new useLazyQuery was added (by @FredyC I think?), and it could be useful to solve this problem: keep a query, but actually execute it after user press a button. Unlike mutations, it does not return a promise when executed. I suggest the following should be possible: ![image](https://user-images.githubusercontent.com/749374/64979571-47b2e800-d8b8-11e9-9991-f082ee4879f7.png) **edit**: actually the screenshot is wrong but you probably understand the point of returning a promise instead of void here (at least in TS typings) Note other apis do return a promise when called (see "refetch" for example). I think useLazyQuery should follow the exact same convention and not return void.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue