-
AbstractI am using urql together with a React app and I am desperately trying to pass a Examplehttps://codesandbox.io/s/blue-morning-mtfj80?file=/src/App.js What the example doesWhen pressing the button, the following things happen:
When following the console output (or your network log) you will see that the urql query is never canceled. I suppose that is because the signal that I pass to the context is copied somewhere along the way and thus is no longer associated with the controller instance. My questionSo my question is: How am I supposed to abort pending requests with an abort signal? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
There are three different cases here, and I'll ignore the specific framework bindings (like the bindings for React, for instance):
In the first case, whenever the subscription to the result disappears, e.g. However, in the second case, once you basically use the promisifying request, or are using the Wonka streams and aren't unsubscribing, the result will be ongoing and no teardown event will be issued. The situation does change however with mutations. In Although, in theory, you can still issue the teardown event manually, I'd simply recommend you not to do this and treat mutations as fire-and-forget events you're sending to your GraphQL API. As per the cancellation in general, there's more details here: https://formidable.com/open-source/urql/docs/architecture/ It's also worth mentioning though that we don't make the assumption that your GraphQL operations are exclusively sent via HTTP (since the transport could be anything else as well, e.g. WebSockets), hence the API is not HTTP specific. In your example for instance, you're passing the That said though, the |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the thorough explanation and background information! I'll do as you said and treat mutations as fire-and-forget events then. In my real application I was passing the |
Beta Was this translation helpful? Give feedback.
There are three different cases here, and I'll ignore the specific framework bindings (like the bindings for React, for instance):
useQuery
orclient.query
)client.query(...).toPromise()
)In the first case, whenever the subscription to the result disappears, e.g.
useQuery
is unmounted, then theClient
will issue a teardown event and ensure that ongoing requests are cancelled and notify the cache that you're not interested in any further updates.However, in the second case, once you basically use the promisifying request, or are using the Wonka streams and aren't unsubscribing, the result w…