After canceling the function that is returned by useLazyQuery with AbortController, I want to execute the function again, but the request is not being sent. Is there a way to resend the request?
Thanks in advance.
After canceling the function that is returned by useLazyQuery with AbortController, I want to execute the function again, but the request is not being sent. Is there a way to resend the request?
Thanks in advance.
Could you please provide a small CodeSandbox that shows this behavior? You can use this CodeSandbox to get started.
Thank you, lenz!!!
Here is a sample app.
In a dev tool, it is easier to replicate by slowing down the network speed.
I see.
Maybe I can give you a bit of a different mindset here to explain that behavior:
The purpose of useLazyQuery
is to have a useQuery
function that doesn’t execute the first time it is rendered. Instead of passing in variables
, you pass those to the execute
function. When you call the execute
function, the variables
will be set internally, and from that moment on, everything happens as it would in useQuery
.
In your case, your query failed, but variables
have been set. Calling execute
again with the same variables will not change anything - and as a result, no new query will be triggered.
On your side, that means that in that case you have to call result.refetch()
instead of execute
to really trigger that query again.
Thank you very much for the great learning experience.
I was completely mistaken about the behavior of useLazyQuery
.
So, I will consider another method.