Netflix / dgs-framework

GraphQL for Java with Spring Boot made easy.
https://netflix.github.io/dgs
Apache License 2.0
3.03k stars 286 forks source link

feature: subscription HTTP callback support #1771

Open dariuszkuc opened 6 months ago

dariuszkuc commented 6 months ago

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

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.

srinivasankavitha commented 6 months ago

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

dariuszkuc commented 6 months ago

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

gwardwell commented 4 months ago

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?

srinivasankavitha commented 4 months ago

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

gwardwell commented 3 months ago

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

paulbakker commented 3 months ago

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