Module: GraphQL::Streaming::AssignSubscriptionField

Defined in:
lib/graphql/streaming/assign_subscription_field.rb

Defined Under Namespace

Classes: SubscriptionResolve

Class Method Summary collapse

Class Method Details

.call(*args, &block) ⇒ Object

Wrap resolve_proc with subscription registration logic.

Examples:

Lookup a post and subscribe to it

subscription :post, PostType do
  argument :id, !types.Int
  resolve -> (obj, args, ctx) {
    Post.find(args[:id])
  end
end


13
14
15
16
17
18
19
20
21
# File 'lib/graphql/streaming/assign_subscription_field.rb', line 13

def self.call(*args, &block)
  underlying_field = GraphQL::Define::AssignObjectField.call(*args, &block)
  # ensure defined
  # TODO: resolve_proc should be a lazy attr reader
  field_name = underlying_field.name
  original_resolve = underlying_field.resolve_proc
  underlying_field.resolve = SubscriptionResolve.new(field_name, original_resolve)
  # Field was assigned to type_defn in AssignObjectField
end