Class: Rails::GraphQL::Subscription::Store::Base

Inherits:
Object
  • Object
show all
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

Memory

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newObject

Make sure that abstract classes cannot be instantiated

Raises:



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

Raises:

  • (NotImplementedError)


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

#allObject

Return all the sids stored

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


82
83
84
# File 'lib/rails/graphql/subscription/store/base.rb', line 82

def search(**options, &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

Raises:

  • (NotImplementedError)


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