aaronwlee/oak-graphql

Subscription example

Opened this issue · 3 comments

Could you please provide an example of using graphql subscription?

Currently, you can define subscriptions in your schema, but this module does not yet implement the WS service for Oak.
i.e you can see the subscription in the playground, but cannot create the connection to get real-time updates.

#7
for more details.

Just sharing because I would like to see this feature in the future.

@aaronwlee perhaps you can add a feature request label to this thread?

Seems it will need something like subscriptions-transport-ws implemented in the applyGraphQL function

It may be out of the scope of this project, but this functionality sure would be a strong selling point to choosing a deno-oak-graphql back-end for a project

Hi, @dev-newman, @jschrbr

I've been tried to implement this subscription function for a while, but I failed due to the technical issues.
Deno std library is not fully compatible with ws.js, thus the apollo client can't reaching out to the proper protocol.

Also, I was tried importing the ws.js from the CDN, but these modules are only working for the browser (they intentionally block this).

If users are using a separate WebSocket module for the subscription connecting, I can create a connection between them.
As far as I know, Deno does not have formalized front-end frameworks as well as GraphQL modules for the client.

In a nutshell, I'll wait for someone do port the ws.js project or Deno supports the node's ws.js module.

Hey @aaronwlee, I've been looking into this a little bit. I've learned a few things just from experimentation and browsing. Let me know if this summary is about right:

GraphQL clients expect an order of operations on top of the usual WebSockets upgrade path (HTTP request with upgrade header). The subscriptions-transport-ws package implements both the client and server sides for this, but is not built for Deno. I see that the contents of that package are included in oak-graphql. I'm guessing at some point you attempted to convert this package to work with Deno and gave up at some point?

I suspect that grokking the "handshake" process for GraphQL subscriptions shouldn't be too bad, since subscriptions-transport-ws is really quite small. I don't fully understand what you mean about ws.js though. The process for actually upgrading a connection to WS using Oak seems sound to me, and I can easily set up such a connection. The rest should just be responding to messages along the socket according to how the client expects, which I understand is the job of subscriptions-transport-ws.

As a side note, the subscriptions-transport-ws repo (linked above) mentions that it is no longer maintained and instead graphql-ws should be used. This however would probably be even harder to port to Deno, since it has a bunch of dependencies. Here's a related blog post: https://the-guild.dev/blog/graphql-over-websockets

I might be able to find the time to attempt recreating the "handshake". If I do, I'll let you know how it goes.