https://github.com/github0013/graphql_subscription_actioncable
a sample repo of how to use subscription with graphql-ruby + apollo2
https://github.com/github0013/graphql_subscription_actioncable
Last synced: 12 months ago
JSON representation
a sample repo of how to use subscription with graphql-ruby + apollo2
- Host: GitHub
- URL: https://github.com/github0013/graphql_subscription_actioncable
- Owner: github0013
- Created: 2018-08-21T10:06:08.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-29T01:14:16.000Z (almost 8 years ago)
- Last Synced: 2025-07-03T22:42:46.901Z (12 months ago)
- Language: Ruby
- Size: 51.8 KB
- Stars: 0
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HOW TO USE GRAPHQL SUBSCRIPTION
This repo is using
- rails
- [graphql-ruby](https://github.com/rmosolgo/graphql-ruby)
- [apollo2](https://www.apollographql.com/docs/react/essentials/get-started.html#installation)
- [ActionCable](http://graphql-ruby.org/javascript_client/apollo_subscriptions#apollo-2--actioncable)
## JUST TRY IT OUT
```bash
git clone https://github.com/github0013/graphql_subscription_actioncable.git
cd graphql_subscription_actioncable
rails s
```
then open `http://localhost:3000/`.
You should only see this.

Open another terminal and run
```bash
rails c
> GraphqlSubscriptionActioncableSchema.subscriptions.trigger('testSub', {}, Time.now.to_i)
```
then you should see a timestamp number on the page.

## THINGS TO CHECK WHEN YOU IMPLEMENT GRAPHQL SUBSCRIPTION
- [check ActionCable's allowed origins](https://guides.rubyonrails.org/action_cable_overview.html#allowed-request-origins)
- [check cable.yml](https://guides.rubyonrails.org/action_cable_overview.html#adapter-configuration)
**be sure to use anything other than `adapter: async`**
- don't just copy [GraphqlChannel sample](http://graphql-ruby.org/api-doc/1.8.7/GraphQL/Subscriptions/ActionCableSubscriptions) as is. It needs some changes.
## check the git log
I kept commands I ran in the log. It should self-explanatory.