gql-dart / gql

Libraries supporting GraphQL in Dart
MIT License
268 stars 124 forks source link

allow cancellation of call using dio cancellation #408

Closed rgplvr closed 1 year ago

rgplvr commented 1 year ago

allow cancellation of call using dio cancellation

knaeckeKami commented 1 year ago

Hello, thanks for the PR. It seems there is an issue with the CI, looks like a breaking change in one of the dependencies of multipack. I'll try to fix it.

Support for cancellation in Dio is good, but is passing a signal cancel token for all requests of the link the right approach?

You can only cancel the token once, right?

I think a better solution would be to pass the cancel token via the context. Then the client code could either create a new cancel token for each request or re-use the same token for multiple requests if preferred.

See e.g. https://github.com/gql-dart/gql/blob/master/links/gql_dio_link/lib/src/dio_link.dart#L312


class DioLinkCancelTokenContextEntry extends ContextEntry {

     final CancelToken token;

     ...
}

in DioLink:


...
final cancelToken = request.context.entry<DioLinkCancelTokenContextEntry>();

...
rgplvr commented 1 year ago

Makes sense. I have made the changes to push the cancellation token to the context entry.

knaeckeKami commented 1 year ago

please update your branch from master to fix the ci issues

rgplvr commented 1 year ago

done

rgplvr commented 1 year ago

made the changes the source is properly formatted as per the diff

knaeckeKami commented 1 year ago

Thanks, LGTM