52 lines
1.6 KiB
Markdown
52 lines
1.6 KiB
Markdown
# GraphQL-WS Proof of Concept
|
|
|
|
This is a simple test script to verify we can send messages to Kosmi using the WebSocket GraphQL API directly, following the `graphql-ws` protocol.
|
|
|
|
## What This Tests
|
|
|
|
1. Connects to Kosmi's WebSocket endpoint (`wss://engine.kosmi.io/gql-ws`)
|
|
2. Follows the graphql-ws protocol:
|
|
- Sends `connection_init`
|
|
- Waits for `connection_ack`
|
|
- Sends a mutation using `subscribe` message type
|
|
3. Attempts to send "Hello World from GraphQL-WS! 🎉" to the chat
|
|
|
|
## Protocol Details
|
|
|
|
Kosmi uses the [graphql-ws protocol](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md), which is different from the older `subscriptions-transport-ws`.
|
|
|
|
Key differences:
|
|
- Uses `graphql-transport-ws` subprotocol
|
|
- Both queries/mutations AND subscriptions use `type: "subscribe"`
|
|
- Must send `connection_init` before any operations
|
|
|
|
## Running the Test
|
|
|
|
```bash
|
|
# From the project root
|
|
go run cmd/test-graphql-ws/main.go
|
|
```
|
|
|
|
## Expected Behavior
|
|
|
|
If successful, you should see:
|
|
1. ✅ WebSocket connected
|
|
2. ✅ Connection acknowledged by server
|
|
3. ✅ Message sent
|
|
4. 📨 Response from server (either success or error)
|
|
|
|
## What We're Testing
|
|
|
|
This will help us determine if:
|
|
- We can connect to Kosmi's WebSocket without browser automation
|
|
- The authentication works (or what auth is needed)
|
|
- We can send messages via GraphQL mutations over WebSocket
|
|
- We can replace the UI automation approach with direct WebSocket
|
|
|
|
## Notes
|
|
|
|
- Change `roomID` in the code to match your Kosmi room
|
|
- The script will keep running until you press Ctrl+C
|
|
- All messages are logged for debugging
|
|
|