Comments (7)
Hi
The WebSocketLink
has dispose()
; I suggest adding dispose()
to the Link
interface class and implement it on other links.
If this is OK I will do it.
from gql.
@agent3bood dispose()
is for disposing the connection to the server, not individual requests.
I think in the subscription case, we should add an unsubscribe
or stop
callback to the response context that sends a send a GQL_STOP
message with the original id
. We could also extend Stream
with an unsubscribe
callback.
One thing I considered but decided against: Having identical subscription requests map to the same id, and then a StopSubscription
request context to cancel. The problem is that that results in potentially unrelated code cancelling each other's subscription.
Anyhow, I don't think graphql/client.dart
doesn't have this ability either right now either, so I'm not too concerned
from gql.
A single steam at the WebSocketLink
might be used by multiple listeners at the client. So I think StreamSubscription
should be used to cancel a stream at the client and the link should follow the state of it's stream to know if the subscription should be closed.
from gql.
Thanks for the feedback.
To close a graphQL subscription the client has to send this message
{
"type": "stop",
"id": "123"
}
The current code will handle closing the stream once it is confirmed by the server.
Thinking of a pretty way to implement this!
- The code that request closing the connection must have the id of the operation (can be added to the
response.context
). - Then we can do
myLink.stop(id)
.
PS:
The client has to send the stop
command so that the server will not be sending unnecessary updates.
from gql.
Another approach could be to cancel a subscription automatically once nobody is listening anymore.
Ferry currently does not support this, but my PR https://github.com/gql-dart/ferry/pull/52/files would enable ferry the send the "onCancel" event to the link, which could then clean up its resources.
from gql.
Update:
We have 3 links and each link should have its own implementation for cancelling.
-
gql_htt_link
This issue is not relevant to this link, because the network request is not a stream.
https://github.com/gql-dart/gql/blob/master/links/gql_http_link/lib/src/link.dart#L168 -
gql_websocket_link
Tis feature is already implemented.
https://github.com/gql-dart/gql/blob/master/links/gql_websocket_link/lib/src/link.dart#L186 -
gal_dio_link
There is an issue open related to this
#180
@smkhalsa Please provide your feedback if we can close this issue, as Ferry is the main user of the links.
from gql.
I haven't been involved in the development of the link packages, so I'll defer to the others on this thread.
from gql.
Related Issues (20)
- [gql_websocket_link] TransportWebSocketLink does not reconnect when graphql server disappears HOT 6
- [graphql_transport_ws] The new subprotocol doesn't auto-reconnect HOT 2
- OperationException(linkException: ResponseFormatException(originalException: type 'Null' is not a subtype of type 'String' in type cast HOT 1
- [Begging for support] Can the url be transformed? HOT 2
- [Support request] How can the client complete a subscription HOT 1
- [gql_websocket_link] Crash events on host lookup HOT 3
- LinkException as a sealed class HOT 2
- [WebSocketLink] inactivityTimeout causes a reconnect HOT 5
- More maintainers wanted
- gql_code_builder: allow adding custom builder factories for nested collections
- [gql_websocket_link] uuid package version conflict HOT 1
- [Question] Dio interceptor with retry not triggered when timeout() is invoked HOT 5
- dependencies issue HOT 1
- FR: Dynamic header HOT 1
- Issue with - distinguishing between null and absent values HOT 3
- How to make reconnect TransportWebSocketLink(TransportWsClientOptions())
- [BUG] Printer fails with string blocks HOT 5
- Type exception in gql_websocket_link with decoding incoming messages. HOT 1
- extract serializers from gql_code_builder to another package
- how to set headers in first http1.1 request before connection upgrade for TransportWebSocketLink?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gql.