Skip to content

Commit ffaf80d

Browse files
author
Garrett Moseke
committed
docs: update readme with example
1 parent 4d44255 commit ffaf80d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ This DataSync fork allows for `Next` messages to be handled by the Server with a
1515

1616
The Client implemeneted here now also supports sending `Next` messages to the server via adding an `Observable` object, which will automatically wrap and send `Next` frames as it updates.
1717

18+
### Example
19+
*The client and the server has already gone through [successful connection initialisation.](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md#successful-connection-initialisation)*
20+
1. *Client* generates a unique ID for the following operation
21+
2. *Client* dispatches the `Subscribe` message with the generated ID through the `id` field and the requested operation passed through the `payload` field
22+
*All future communication is linked through this unique ID*
23+
3. *Server* executes the streaming GraphQL operation
24+
4. *Server* checks if the generated ID is unique across active streaming subscriptions
25+
- If not unique, the server will close the socket with the event `4409: Subscriber for <generated-id> already exists`
26+
If unique, continue...
27+
5. *Server* optionally checks if the operation is valid before starting executing it, e.g. checking permissions
28+
- If not valid, the server sends an `Error` message and deems the operation complete.
29+
If valid, continue...
30+
6. *Server* & *Client* dispatch results over time with the `Next` message
31+
- *Server* & *Client* handle received `Next` messages with their respectively defined callbacks. All Context is assumed to be the same between the two and is established in step 3 when the subscription is created.
32+
7. The operation completes as described in [the `graphql-transport-ws` protocol](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md#streaming-operation)
33+
1834
## Usage
1935

2036
To use this package, include it in your `Package.swift` dependencies:

0 commit comments

Comments
 (0)