https://github.com/graphql-compose/graphql-compose-subscription-boilerplate
GraphQL-compose boilerplate with subscriptions
https://github.com/graphql-compose/graphql-compose-subscription-boilerplate
Last synced: 11 days ago
JSON representation
GraphQL-compose boilerplate with subscriptions
- Host: GitHub
- URL: https://github.com/graphql-compose/graphql-compose-subscription-boilerplate
- Owner: graphql-compose
- Created: 2018-04-27T15:22:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-28T10:52:19.000Z (about 7 years ago)
- Last Synced: 2025-06-01T07:44:25.882Z (24 days ago)
- Language: JavaScript
- Homepage:
- Size: 48.8 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# graphql-compose-subscription-boilerplate
## Includes
* Babel (ES6, babel-preset-env)
* ESLint
* Flowtype
* express
* apollo-server-express
* graphql
* graphql-compose
* graphql-subscriptions
* subscriptions-transport-ws
* nodemon## Usage
```bash
git clone https://github.com/graphql-compose/graphql-compose-subscription-boilerplatecd graphql-compose-subscription-boilerplate
# make it to your own
rm -rf .gityarn install
# start server with reloading on file changes
yarn dev# OR start server
yarn start
```## How to subscribe
1. Describe your subscription like below
```js
schemaComposer.Subscription.addFields({
updatePost: {
type: 'Post',
resolve: payload => {
return payload.updatePost;
},
subscribe: () => pubsub.asyncIterator('updatePost'),
},
});
```As you noticed, PubSub library is used that will help you.
2. In your mutation, specify the data that you want to subscribe to.
```js
...
pubsub.publish('updatePost', { updatePost: post });
...
```Now, when a mutation invokes, Subscription will watch and report changes in the data.
3. Customize server part like in boilerplate.
Pay attention, in comparison with the usual server for GraphQL, there is `SubscriptionServer` and `subscriptionsEndpoint`.