Created
November 15, 2017 14:11
-
-
Save timsuchanek/3a01f4b7246091ebe107f0638918137a to your computer and use it in GitHub Desktop.
Minimal GraphQL Subscription working with subscriptions-transport-ws 0.9.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Websockets Test</title> | |
</head> | |
<body> | |
<script> | |
const socket = new WebSocket( | |
'wss://subscriptions.graph.cool/v1/cirs1ufsg02b101619ru0bx5r','graphql-ws' | |
) | |
socket.addEventListener('open', event => { | |
console.log('open') | |
console.log(event) | |
socket.send(JSON.stringify({type: 'connection_init'})) | |
}) | |
socket.addEventListener('message', event => { | |
console.log('message') | |
console.log(event) | |
const data = JSON.parse(event.data) | |
if (data.type === 'connection_ack') { | |
const request = { | |
type: 'start', | |
id: '0', | |
payload: { | |
query: `subscription { | |
B { | |
node { | |
id | |
} | |
} | |
}` | |
} | |
} | |
socket.send(JSON.stringify(request)) | |
} | |
}) | |
socket.addEventListener('error', event => { | |
console.log('error') | |
console.log(event) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see https://gist.github.com/marktani/5df524523693c88be425bfb623ca8b8a for an example with the
Authorization
connection parameter