Created
October 2, 2016 16:51
-
-
Save stubailo/8b7ff3b60221e0d648a50f9bc8065e89 to your computer and use it in GitHub Desktop.
Use subscriptions-transport-ws to run a GraphQL subscription from a JavaScript client.
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
// To run this code yourself: | |
// 1. Download and run the demo server: https://github.com/apollostack/frontpage-server | |
// 2. Use create-react-app to create a build system | |
// 3. npm install subscriptions-transport-ws | |
// 4. Replace all of the code in src/ with just this file | |
import { Client } from 'subscriptions-transport-ws'; | |
const client = new Client('ws://localhost:8090'); | |
client.subscribe({ | |
query: ` | |
subscription UpvotedPostSubscription { | |
postUpvoted { | |
title | |
votes | |
} | |
} | |
` | |
}, (err, res) => { | |
if (err) { | |
console.error(err); | |
return; | |
} | |
console.log(`"${res.postUpvoted.title}" has ${res.postUpvoted.votes} votes now.`); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, I've got an error of:
"Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory."
Still I don't know how to use subscriptions. :'( My issue is here: https://github.com/apollostack/GitHunt-React/issues/156