-
-
Notifications
You must be signed in to change notification settings - Fork 521
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
useQuery
and useLazyQuery
should also return a promise
#1486
useQuery
and useLazyQuery
should also return a promise
#1486
Comments
For now you can do: function waitApolloQuery({ onResult, onError }) {
return new Promise((res, rej) => {
const { off: offResult } = onResult((result) => {
offResult()
res(result)
})
const { off: offError } = onError((error) => {
offError()
rej(error)
})
})
}
const query = useLazyQuery()
try {
query.load()
const data = await waitApolloQuery(query)
} catch(e) {
// Handle error
} |
|
You can make sure the promise is only resolved when the query is no longer loading. const { off: offResult } = onResult((result) => {
+ if (result.loading === false) {
offResult()
res(result)
+ }
}) |
@sschneider-ihre-pvs That is a different issue, Also, this is the final implementation of waitForApolloQuery that ended up working for me:
Usage of |
The problem is that i still want to wait for a specific request made by the lazy query.
Because
load
doesn't return the current request promise, many reactive variables needed to be watched unwillingly.The suggested solution
load()
should return the promise to the current request.also every other fetching function like
rerun
etc.The text was updated successfully, but these errors were encountered: