Skip to content

Conversation

@lewinpauli
Copy link

@lewinpauli lewinpauli commented Dec 3, 2025

As needed since 6 years here is cancellation support #181

  • Add CancellationToken class for operation cancellation
  • Add CancelledException for cancelled operations
  • Integrate cancellation into BaseOptions, QueryOptions, MutationOptions
  • Implement cancellation handling in QueryManager
  • Add queryCancellable() and mutateCancellable() convenience methods
  • Add comprehensive test suite (7 tests)
  • Add usage documentation

-> no breaking changes

-> all tests pass

- Add CancellationToken class for operation cancellation
- Add CancelledException for cancelled operations
- Integrate cancellation into BaseOptions, QueryOptions, MutationOptions
- Implement cancellation handling in QueryManager
- Add queryCancellable() and mutateCancellable() convenience methods
- Add comprehensive test suite (7 tests)
- Add usage documentation

3. **Error Handling**: Cancelled operations will complete with an `OperationException` containing a `CancelledException` as the `linkException`.

4. **Network Cleanup**: Cancelling an operation will attempt to cancel the underlying network request, but depending on the transport layer and server, the request may still complete on the server side.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't really see how it cancels the underlying request? can you explain?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right i haven't noticed that the underlying http request wasn't actually cancelled, only the subscription was cancelled.

I now added true HTTP request cancellation to the graphql package.

  • Created custom HttpLink with platform-specific cancellation support

  • Web: Uses XMLHttpRequest.abort() → shows "(canceled)" in Chrome DevTools

  • IO (Linux/Desktop/Mobile): Uses HttpClient.close(force: true) + request.abort() → terminates TCP connection

  • Added CancellationContextEntry to pass the token through the Link chain

  • Added web package dependency (replaces deprecated dart:html)

  • Added additional tests for http cancellation

Result:

operation.cancel() now actually aborts the underlying HTTP request

Not just ignoring the response — the network connection is terminated

I verified it, in chrome and linux the http request gets actually cancelled

- Created custom HttpLink with platform-specific cancellation support
- Web: Uses XMLHttpRequest.abort() → shows "(canceled)" in Chrome DevTools
- IO (Linux/Desktop/Mobile): Uses HttpClient.close(force: true) + request.abort() → terminates TCP connection
- Added CancellationContextEntry to pass the token through the Link chain
- Added web package dependency (replaces deprecated dart:html)

Result:
operation.cancel() now actually aborts the underlying HTTP request
Not just ignoring the response — the network connection is terminated

MutationOptions<TParsed> copyWithPolicies(Policies policies) =>
MutationOptions(
MutationOptions<TParsed> copyWithPolicies(Policies policies) => MutationOptions(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should run dart format --line-length=80 ./

There is quite a lot of irrelevant white space noise in this PR

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

Successfully merging this pull request may close these issues.

2 participants