Skip to content

Feature/add cancellation support#1510

Open
lewinpauli wants to merge 5 commits intozino-hofmann:mainfrom
lewinpauli:feature/add-cancellation-support
Open

Feature/add cancellation support#1510
lewinpauli wants to merge 5 commits intozino-hofmann:mainfrom
lewinpauli:feature/add-cancellation-support

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


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


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

@vincenzopalazzo
Copy link
Collaborator

vincenzopalazzo commented Jan 10, 2026

Hi thanks for the contrinbution, this PR is not getting any review because I was not pinged by my internal review bot due that commits are not following the contribution guidelines. I suggest you add it to the claude.md or any other agent.md file because following the commit style is what get any PR merged in a couple of hours or delayed months.

Sorry

for commit style see https://github.com/zino-hofmann/graphql-flutter/blob/main/docs/dev/MAINTAINERS.md#commit-style

@lewinpauli lewinpauli force-pushed the feature/add-cancellation-support branch from 8a0d116 to e4e05cf Compare January 12, 2026 17:37
@jorg1piano
Copy link

I'm very skeptical of this approach.

It does not seem to consider how this would work with observables. It also does not really play well with the cache; any cancellation that does not know about the link and the cache will not work in a nice way when you throw streams into the mix.

It also makes me very skeptical because, when I looked at the original PR, it did not actually do what it claimed it did, which makes me think "AI slop" right away.

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.

3 participants