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

documentation: SSE Subscriptions documentation & example

Open ddalcu opened this issue 4 years ago • 13 comments

Do you have an example for both on the Server Side & Client side (Vanilla JS preferred) on how to do SSE Subscriptions using DGS ?

ddalcu avatar Apr 05 '21 18:04 ddalcu

We don't have an example documented yet. Thanks for reporting, we will add this.

srinivasankavitha avatar Apr 05 '21 20:04 srinivasankavitha

is it possible ? Maybe pointing to an example while the documentation is being written out ?

ddalcu avatar Apr 21 '21 21:04 ddalcu

Apologies for the delay. We don't have an example ready yet to be shared as it is currently custom to our internal use case. We will share it once we have something. Owing to higher priority issues, we haven't been able to get to this yet.

srinivasankavitha avatar Apr 22 '21 19:04 srinivasankavitha

It seems the SSE is only designed for traditional WebMvc applications.

In my opinion, SSE/WebSocket(if Dgs team plans to support both protocols) should be implemented in WebMvc and WebFlux respectively, not the current state.

For developers, I hope there is a PubSub like tool to simplify the usage of resolve Subscription type.

hantsy avatar Jun 13 '21 11:06 hantsy

And there is no simple method in the DgsQueryExecutor to handle subscribing actions to a GraphQL Subscription in the client view.

hantsy avatar Jun 13 '21 12:06 hantsy

I created an example of sse subscription.

I have a UI client to demo subscription in the same repo, but it used Angular GraphQL and WebSocket.

For the client UI example for SSE, I think you can have a look at another example of mine. Send the raw JSON request to /graphql, and subscribe /subsctptions endpoint.

hantsy avatar Jun 17 '21 17:06 hantsy

@srinivasankavitha are there any updates to this? Does dgs support sse for subscriptions and if not can we reuse this issue for it or should I create a new issue?

Ancient-Dragon avatar Jun 26 '22 14:06 Ancient-Dragon

@Ancient-Dragon Dgs support SSE in the traditional WebMvc stack. Check my example the links in my last comments.

hantsy avatar Jun 26 '22 14:06 hantsy

@hantsy Apologies I'm not familiar with kotlin, I couldn't see where it was setting the fact that it was using SSE rather than websockets. I can see now that it's brought in via dependencies sorry about that! Will this be added to the official documentation (I couldn't find it here either)?

Ancient-Dragon avatar Jun 26 '22 15:06 Ancient-Dragon

@hantsy Did you try this with altair or anything, it keeps throwing the exception that the request that the query parameter is missing, looking into the package it is using @RequestParam which I thought is something that you need to put in the url rather than it reading it from the body of the request.

Screenshot 2022-06-27 at 12 52 09 Screenshot 2022-06-27 at 12 51 47 Screenshot 2022-06-27 at 12 50 41

Ancient-Dragon avatar Jun 27 '22 09:06 Ancient-Dragon


Regards,

Hantsy Bai

Self-employed consultant, fullstack developer, agile coach, freelancer/remote worker

GitHub: https://github.com/hantsy

Twitter: @.*** Medium: @.***

I have written tests for it, https://github.com/hantsy/spring-graphql-sample/tree/master/dgs-subscription-sse/src/test/kotlin/com/example/demo

On Mon, Jun 27, 2022 at 5:59 PM Ancient-Dragon @.***> wrote:

@hantsy https://github.com/hantsy Did you try this with altair or anything, it keeps throwing the exception that the request that the query parameter is missing, looking into the package it is using @RequestParam https://github.com/RequestParam which I thought is something that you need to put in the url rather than it reading it from the body of the request.

[image: Screenshot 2022-06-27 at 12 52 09] https://user-images.githubusercontent.com/22601875/175915318-e71f3d29-519c-414b-87d4-2d78be1e22f7.png

[image: Screenshot 2022-06-27 at 12 51 47] https://user-images.githubusercontent.com/22601875/175915323-8a9cb583-d7b0-4c19-9f62-211c39acec6f.png

[image: Screenshot 2022-06-27 at 12 50 41] https://user-images.githubusercontent.com/22601875/175915348-4acf73c7-fcc0-43ca-9fa1-841f138e32cc.png

— Reply to this email directly, view it on GitHub https://github.com/Netflix/dgs-framework/issues/236#issuecomment-1167146699, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGQT6FKS73NYEQO5WBN3W3VRF3R5ANCNFSM42NGV5SA . You are receiving this because you were mentioned.Message ID: @.***>

hantsy avatar Jun 27 '22 10:06 hantsy

Ah I can see that you've used the dgs SSE client which was written afterwards and seems to turn the requests into get ones with a query parameter. Based on a quick look at the SSE js library it looks like it POST requests should be supported. I'll try and setup a really simple demo with vue and the js library.

Ancient-Dragon avatar Jun 27 '22 12:06 Ancient-Dragon

I was able to confirm it with a basic example here (backend): https://github.com/Ancient-Dragon/dgs-sse-subscriptions-backend-example and here (frontend): https://github.com/Ancient-Dragon/dgs-sse-subscriptions-post-example

To run you just need to run the backend and the dev command in frontend as well as the server command and it should give you the error I was referring to.

Ancient-Dragon avatar Jun 27 '22 14:06 Ancient-Dragon