CancellableHttpLink class

An HTTP link that supports request cancellation.

This link provides the same functionality as HttpLink from gql_http_link but adds support for cancelling in-flight HTTP requests when a CancellationToken is present in the request context.

Uses http.AbortableRequest from the http package (>=1.6.0) to perform true network-level cancellation on all platforms. When the cancellation token fires, the abortTrigger future completes, causing the standard HTTP client to abort the underlying connection.

Usage

final link = CancellableHttpLink('https://api.example.com/graphql');
final client = GraphQLClient(
  cache: GraphQLCache(),
  link: link,
);

// Use queryCancellable/mutateCancellable for automatic cancellation token:
final operation = client.queryCancellable(QueryOptions(...));
operation.cancel(); // Actually cancels the HTTP request

// Or provide a CancellationToken manually:
final token = CancellationToken();
client.query(QueryOptions(
  ...,
  cancellationToken: token,
));
token.cancel(); // Actually cancels the HTTP request

File Uploads

This link fully supports file uploads using the GraphQL multipart request specification, the same as the standard HttpLink.

Maintenance

Keep in sync with gql_http_link's HttpLink: this link deliberately mirrors upstream header handling, GET-for-queries encoding, multipart mapping, and response parsing. Behavior changes or bug fixes landing in gql_http_link.HttpLink should be reflected here until abortTrigger support is upstreamed and this fork can be removed.

Inheritance

Constructors

CancellableHttpLink(String uri, {Map<String, String> defaultHeaders = const {}, bool useGETForQueries = false, RequestSerializer serializer = const RequestSerializer(), ResponseParser parser = const ResponseParser(), HttpResponseDecoder httpResponseDecoder = _defaultHttpResponseDecode, bool followRedirects = false})
Creates a new CancellableHttpLink.

Properties

defaultHeaders → Map<String, String>
Default HTTP headers to include in every request.
final
followRedirects → bool
Whether to follow redirects.
final
hashCode → int
The hash code for this object.
no setterinherited
httpResponseDecoder → HttpResponseDecoder
Decoder for HTTP response bodies.
final
parser → ResponseParser
Parser for converting HTTP response bodies to GraphQL responses.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serializer → RequestSerializer
Serializer for converting GraphQL requests to HTTP request bodies.
final
uri → Uri
The endpoint URI of the GraphQL service.
final
useGETForQueries → bool
Whether to use HTTP GET method for queries (not mutations).
final

Methods

concat(Link next) → Link
Adds next after this link
inherited
dispose() → Future<void>
Can be called to clean up resources
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
request(Request request, [NextLink? forward]) → Stream<Response>
A function called when a request reaches this Link
override
route(LinkRouter route) → Link
Route requests after this link
inherited
split(bool test(Request request), Link left, [Link right = const PassthroughLink()]) → Link
Split requests after this link
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited