TL DR: You can use graphql-up to quickly get a GraphQL server with support for subscribing up and ready. Here's a more detailed guide on using this in conjunction with Apollo and the websocket subscriptions-transport-ws client.
Get GraphQL server with one click
Suppose you want to create a Twitter clone based on this GraphQL Schema in IDL syntax :
type Tweet { id: ID! title: String! author: User! @relation(name: "Tweets") } type User { id: ID! name: String! tweets: [Tweet!]! @relation(name: "Tweets") }

Click this button to get your own GraphQL API, and then open the Playground, where you can add some tweets, request all tweets, and also check your subscriptions.
Easy to use API
First create a user who will be the author for all upcoming tweets. Run this mutation on the playground:
mutation createUser { createUser(name: "Tweety") { id # copy this id for future mutations! } }
Here you request all the tweets and their authors stored on your GraphQL server:
query allTweets { allTweets { id title createdAt author { id name } } }
Web Card Subscription Support
Now subscribe to the new Tweety tweets. This is the syntax:
subscription createdTweets { Message(filter: { mutation_in: [CREATED] node: { author: { name: "Tweety" } } }) { node { id text createdAt sentBy { id name } } } }
Now create a new tab on the playground and create a new tweet:
mutation createTweet { createTweet( title: "#GraphQL Subscriptions are awesome!" authorId: "<id-from-above>" ) { id } }
You should see a new event appearing on another tab that you subscribed to earlier.
source share