Class: Rails::GraphQL::Subscription::Store::Base
- Inherits:
-
Object
- Object
- Rails::GraphQL::Subscription::Store::Base
- Defined in:
- lib/rails/graphql/subscription/store/base.rb
Overview
GraphQL Base Subscription Store
The base class for all the other subscription stores, which defines the necessary interfaces to keep track of all the subscriptions
Be careful with each subscription context. Although there are ways to clean it up (by implementing a subscription_context
callback into the field), it is still the most dangerous and heavy object that can be placed into the store. The problem with in memory store is that it does not work with a Rails application running cross-processes. On the other hand, file, Redis, or Database-based stores can find it difficult to save the context and bring it back to Rails again
The closest best way to be safe about the context is relying on ActiveJob::Arguments
to serialize and deserialize it (which aligns with all possible arguments that jobs and receive and how they are usually properly stored in several different providers for ActiveJob)
Direct Known Subclasses
Class Method Summary collapse
-
.new ⇒ Object
Make sure that abstract classes cannot be instantiated.
Instance Method Summary collapse
-
#add(subscription) ⇒ Object
Add a new subscription to the store, saving in a way it can be easily searched at any point.
-
#all ⇒ Object
Return all the sids stored.
-
#fetch(*sids) ⇒ Object
Fetch one or more subscriptions by their ids.
-
#has?(item) ⇒ Boolean
Check if a given sid or instance is stored.
-
#remove(item) ⇒ Object
Remove a given subscription from the store by its id or instance.
-
#search(**options, &block) ⇒ Object
(also: #find_each)
Search one or more subscriptions by the list of provided options and return the list of sids that matched.
-
#serialize(**xargs) ⇒ Object
Get the list of provided
xargs
for search and serialize them. -
#update!(item) ⇒ Object
Marks that a subscription has received an update.
Class Method Details
.new ⇒ Object
Make sure that abstract classes cannot be instantiated
32 33 34 35 36 37 38 |
# File 'lib/rails/graphql/subscription/store/base.rb', line 32 def new(*) return super unless self.abstract raise StandardError, (+" \#{name} is abstract and cannot be used as a subscription store.\n MSG\nend\n").squish |
Instance Method Details
#add(subscription) ⇒ Object
Add a new subscription to the store, saving in a way it can be easily searched at any point
54 55 56 |
# File 'lib/rails/graphql/subscription/store/base.rb', line 54 def add(subscription) raise NotImplementedError, +"#{self.class.name} does not implement add" end |
#all ⇒ Object
Return all the sids stored
48 49 50 |
# File 'lib/rails/graphql/subscription/store/base.rb', line 48 def all raise NotImplementedError, +"#{self.class.name} does not implement all" end |
#fetch(*sids) ⇒ Object
Fetch one or more subscriptions by their ids
59 60 61 |
# File 'lib/rails/graphql/subscription/store/base.rb', line 59 def fetch(*sids) raise NotImplementedError, +"#{self.class.name} does not implement fetch" end |
#has?(item) ⇒ Boolean
Check if a given sid or instance is stored
74 75 76 |
# File 'lib/rails/graphql/subscription/store/base.rb', line 74 def has?(item) raise NotImplementedError, +"#{self.class.name} does not implement has?" end |
#remove(item) ⇒ Object
Remove a given subscription from the store by its id or instance
64 65 66 |
# File 'lib/rails/graphql/subscription/store/base.rb', line 64 def remove(item) raise NotImplementedError, +"#{self.class.name} does not implement remove" end |
#search(**options, &block) ⇒ Object Also known as: find_each
Search one or more subscriptions by the list of provided options and return the list of sids that matched. A block can be provided to go through each of the found results, yield the object itself instead of the sid
82 83 84 |
# File 'lib/rails/graphql/subscription/store/base.rb', line 82 def search(**, &block) raise NotImplementedError, +"#{self.class.name} does not implement search" end |
#serialize(**xargs) ⇒ Object
Get the list of provided xargs
for search and serialize them
43 44 45 |
# File 'lib/rails/graphql/subscription/store/base.rb', line 43 def serialize(**xargs) xargs end |
#update!(item) ⇒ Object
Marks that a subscription has received an update
69 70 71 |
# File 'lib/rails/graphql/subscription/store/base.rb', line 69 def update!(item) raise NotImplementedError, +"#{self.class.name} does not implement update!" end |