Sha256: 6113c9b0e096b4fc8761046d79b2164c10282ecb96cd99ea8d321142e230b44f

Contents?: true

Size: 952 Bytes

Versions: 52

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  class Subscriptions
    # Wrap the root fields of the subscription type with special logic for:
    # - Registering the subscription during the first execution
    # - Evaluating the triggered portion(s) of the subscription during later execution
    class Instrumentation
      def initialize(schema:)
        @schema = schema
      end

      # If needed, prepare to gather events which this query subscribes to
      def before_query(query)
        if query.subscription? && !query.subscription_update?
          query.context.namespace(:subscriptions)[:events] = []
        end
      end

      # After checking the root fields, pass the gathered events to the store
      def after_query(query)
        events = query.context.namespace(:subscriptions)[:events]
        if events && events.any?
          @schema.subscriptions.write_subscription(query, events)
        end
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
graphql-2.1.13 lib/graphql/subscriptions/instrumentation.rb
graphql-2.0.31 lib/graphql/subscriptions/instrumentation.rb
graphql-2.0.29 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.12 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.11 lib/graphql/subscriptions/instrumentation.rb
graphql-2.0.28 lib/graphql/subscriptions/instrumentation.rb
graphql-2.2.5 lib/graphql/subscriptions/instrumentation.rb
graphql-2.2.4 lib/graphql/subscriptions/instrumentation.rb
graphql-2.2.3 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.10 lib/graphql/subscriptions/instrumentation.rb
graphql-2.2.2 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.9 lib/graphql/subscriptions/instrumentation.rb
graphql-2.2.1 lib/graphql/subscriptions/instrumentation.rb
graphql-2.2.0 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.8 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.7 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.6 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.5 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.4 lib/graphql/subscriptions/instrumentation.rb
graphql-2.1.3 lib/graphql/subscriptions/instrumentation.rb