dgs-framework icon indicating copy to clipboard operation
dgs-framework copied to clipboard

feature: subscription HTTP callback support

Open dariuszkuc opened this issue 1 year ago • 6 comments

Describe the Feature Request

GraphQL subscriptions enable clients to receive continual, real-time updates whenever new data becomes available. Unlike queries and mutations, subscriptions are long-lasting. This means a client can receive multiple updates from a single subscription.

WebSocket is the most commonly used subscription mechanism but it comes with few drawbacks - most notably it requires long lasting open connections. Apollo Router supports subscriptions using both the WebSocket and HTTP callback mechanism. HTTP callback protocol allows GraphQL servers to asynchronously send their subscription updates using regular HTTP POST requests which in turn allows you to scale you servers more easily.

HTTP callback protocol flow

  • initialization
    • router generates new unique subscription ID
    • routers sends subscription operation with additional extension data using regular HTTP POST request
    • subgraph responds with a check message
    • router responds with HTTP 204 (if successful)
    • subgraph responds with empty { "data": null } GraphQL response
  • main loop (run on some background thread)
    • subgraph sends heartbeats every X milliseconds (if enabled)
    • whenever new data is available, subgraph sends next message followed by complete message at the end of the stream

See also:

  • federation-jvm spring-graphl implementation of the protocol [link fix]

Describe Preferred Solution

DGS provides out of the box support for subscriptions using HTTP callback protocol.

Describe Alternatives

WebSocket based subscriptions are still viable option but don't scale as nicely.

dariuszkuc avatar Jan 08 '24 23:01 dariuszkuc

It looks like the PR you created in federation-jvm adds implements support for Http callback protocol for spring-graphql projects. We are currently working on integrating with spring-graphql in the DGS framework. I expect this feature would be available for free when that is released later this quarter. Rather than reimplementing this same logic in the framework, it would be preferable to leverage what is in the federation-jvm library already.

On Mon, Jan 8, 2024 at 3:08 PM Dariusz Kuc @.***> wrote:

Describe the Feature Request

GraphQL subscriptions enable clients to receive continual, real-time updates whenever new data becomes available. Unlike queries and mutations, subscriptions are long-lasting. This means a client can receive multiple updates from a single subscription.

WebSocket is the most commonly used subscription mechanism but it comes with few drawbacks - most notably it requires long lasting open connections. Apollo Router supports subscriptions using both the WebSocket and HTTP callback https://www.apollographql.com/docs/router/executing-operations/subscription-callback-protocol/ mechanism. HTTP callback protocol allows GraphQL servers to asynchronously send their subscription updates using regular HTTP POST requests which in turn allows you to scale you servers more easily.

HTTP callback protocol flow https://www.apollographql.com/docs/router/executing-operations/subscription-callback-protocol/

  • initialization
    • router generates new unique subscription ID
    • routers sends subscription operation with additional extension data using regular HTTP POST request
    • subgraph responds with a check message
    • router responds with HTTP 204 (if successful)
    • subgraph responds with empty { "data": null } GraphQL response
  • main loop (run on some background thread)
    • subgraph sends heartbeats every X milliseconds (if enabled)
    • whenever new data is available, subgraph sends next message followed by complete message at the end of the stream

See also:

Describe Preferred Solution

DGS provides out of the box support for subscriptions using HTTP callback protocol. Describe Alternatives

WebSocket based subscriptions are still viable option but don't scale as nicely.

— Reply to this email directly, view it on GitHub https://github.com/Netflix/dgs-framework/issues/1771, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ5JPXLWCSHGWGJMEGK25I3YNR365AVCNFSM6AAAAABBSGJE6WVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3TCMZWG42DIMY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

srinivasankavitha avatar Jan 08 '24 23:01 srinivasankavitha

👍 Sounds good! Feel free to close the issue (or to keep it around until spring-graphql integration is completed).

dariuszkuc avatar Jan 08 '24 23:01 dariuszkuc

It looks like DGS v8.3.0 updates to federation-jvm v4.4.0. Support for subscription callbacks was added in federation-jvm 4.2.0. Does this mean that DGS should support subscriptions via HTTP callback now? Or is it still blocked by the mentioned spring-graphql support since I see that work is being done in v8.2.6 RC releases?

gwardwell avatar Feb 13 '24 14:02 gwardwell

Support for HTTP callbacks will be available in the spring-graphql integration in a future release, It is not available yet on existing releases.

srinivasankavitha avatar Feb 13 '24 17:02 srinivasankavitha

Does the release of DGS 8.5.0 with Spring GraphQL integration mean subscription HTTP callbacks are now supported?

gwardwell avatar Apr 08 '24 21:04 gwardwell

Yes, with https://github.com/apollographql/federation-jvm?tab=readme-ov-file#subscription-http-callback-support-for-spring-graphql

On Mon, Apr 8, 2024 at 2:50 PM Greg Wardwell @.***> wrote:

Does the release of DGS 8.5.0 https://github.com/Netflix/dgs-framework/releases/tag/v8.5.0 with Spring GraphQL integration mean subscription HTTP callbacks are now supported?

— Reply to this email directly, view it on GitHub https://github.com/Netflix/dgs-framework/issues/1771#issuecomment-2043699450, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2XLCKCMF6IWXKIHLZCH3Y4MGLRAVCNFSM6AAAAABBSGJE6WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBTGY4TSNBVGA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

paulbakker avatar Apr 08 '24 21:04 paulbakker