https://github.com/gingray/ruby-graphql-subscription-client
ruby graphql subsctiption client to test subscription through the ActionCable
https://github.com/gingray/ruby-graphql-subscription-client
actioncable apollo-client apollographql graphql rails ruby subscription
Last synced: about 2 months ago
JSON representation
ruby graphql subsctiption client to test subscription through the ActionCable
- Host: GitHub
- URL: https://github.com/gingray/ruby-graphql-subscription-client
- Owner: gingray
- Created: 2020-07-08T12:47:34.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T19:54:40.000Z (over 3 years ago)
- Last Synced: 2026-02-19T04:30:08.131Z (4 months ago)
- Topics: actioncable, apollo-client, apollographql, graphql, rails, ruby, subscription
- Language: JavaScript
- Homepage: https://github.com/gingray/ruby-graphql-subsctiption-client
- Size: 1.84 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 20
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# GraphQL Subscription test(sandbox) ruby client
It's small test(sandbox) setup for graphql subscription when you use it with
`gem 'graphql'`
**Change urls in `src/index.js` to your endpoints**
To run example:
`npm install`
`npm start`
trigger from Rails console example:
`BackendSchema.subscriptions.trigger(:hello, {}, 'test')`
just mention configs that probably can save you time
```ruby
# app/graphql/backend_schema.rb
class BackendSchema < GraphQL::Schema
# Assume that use ActionCable
use GraphQL::Subscriptions::ActionCableSubscriptions, redis: Redis.new
subscription(Types::SubscriptionType)
# other configs removed to not to distract attention
end
```
```ruby
# app/graphql/types/subscription_type.rb
module Types
class SubscriptionType < Types::BaseObject
field :notify_display, subscription: Subscription::NotifyDisplay
end
end
```
```ruby
# app/graphql/subscription/notify_display.rb
module Subscription
class NotifyDisplay < Subscription::BaseSubscription
argument :display_id, Int, required: true
field :message, String, null: true
def subscribe(display_id:)
:no_response
end
def update(display_id:)
# where object come from its payload which send
# thorugh the trigger function
# https://graphql-ruby.org/subscriptions/triggers.html
{ message: object }
end
end
end
```
```ruby
# config/environments/development.rb
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/, /file:\/\/*/, 'file://']
```
```ruby
# config/application.rb
if Rails.env.test? || Rails.env.development?
config.middleware.insert_before 0, Rack::Cors do
allow do
origins "*"
resource "*", headers: :any, methods: [:get, :post, :options, :patch, :put, :delete]
end
end
end
```
[WARN] this line below put only in development mode with ActionCable
```ruby
# config/routes.rb
mount ActionCable.server, at: '/cable'
```