-
Notifications
You must be signed in to change notification settings - Fork 5
Description
The latest release contains full implementation of Subscriptions, server and full support by GraphQLClient (Client in NGraphQL). Unit tests run successfully using this client.
The question comes about other clients (js/ts in browser) or playground apps like Graphiql. I did not try it yet in playgrounds, but I will in the coming weeks and will report here, if it's doable and how. The situation is that GraphQL spec 'defines' subscriptions, but does not really specify any details of implementation of the actual protocol, so implementations may vary.
Looks like the today the common agreed protocol is this:
https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md
and NGraphQL implementation is based on it, as close as possible.
One important note - the Subscribe message, with subscription query inside, is sent over WebSocket connection, not through GraphQL usual Post request. So do not try to do POST with subscription query, like you do with Query or Mutation - that would not work.
For accessing NGraphQL subscription from JS in the page or other client. Two steps:
- Establish WebSocket connection
- Use the protocol above to exchange json messages over this connection
For item 1, NGraphQL is using SignalR for websockets, so here are the instructions of how to connect to SignalR server from JS:
Edit: NGraphQL subscription endpoint for websockets: /graphql/subscriptions
After connecting, start sending/receiving messages according to the protocol. NGraphQL server supports all message including ConnectionInit, Ping, Subscribe, Complete etc. I am sure there is some ready to use JS/React component doing this, some GraphQL client. Let me know if something does not work.
In the meantime, I will try to play with playgrounds and see if they can make to work with NGraphQL server.