Git Product home page Git Product logo

Comments (7)

agent3bood avatar agent3bood commented on August 18, 2024

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.

micimize avatar micimize commented on August 18, 2024

@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.

klavs avatar klavs commented on August 18, 2024

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.

agent3bood avatar agent3bood commented on August 18, 2024

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!

  1. The code that request closing the connection must have the id of the operation (can be added to the response.context).
  2. 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.

knaeckeKami avatar knaeckeKami commented on August 18, 2024

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.

agent3bood avatar agent3bood commented on August 18, 2024

Update:

We have 3 links and each link should have its own implementation for cancelling.

  1. 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

  2. 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

  3. 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.

smkhalsa avatar smkhalsa commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.