module GraphQL::Streaming::AssignSubscriptionField

Public Class Methods

call(*args, &block) click to toggle source

Wrap resolve_proc with subscription registration logic.

@example 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
# 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