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
- Connects to Kosmi's WebSocket endpoint (
wss://engine.kosmi.io/gql-ws) - Follows the graphql-ws protocol:
- Sends
connection_init - Waits for
connection_ack - Sends a mutation using
subscribemessage type
- Sends
- Attempts to send "Hello World from GraphQL-WS! 🎉" to the chat
Protocol Details
Kosmi uses the graphql-ws protocol, which is different from the older subscriptions-transport-ws.
Key differences:
- Uses
graphql-transport-wssubprotocol - Both queries/mutations AND subscriptions use
type: "subscribe" - Must send
connection_initbefore any operations
Running the Test
# From the project root
go run cmd/test-graphql-ws/main.go
Expected Behavior
If successful, you should see:
- ✅ WebSocket connected
- ✅ Connection acknowledged by server
- ✅ Message sent
- 📨 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
roomIDin the code to match your Kosmi room - The script will keep running until you press Ctrl+C
- All messages are logged for debugging