Sha256: 4fd26ff199a4699d8086ee57ae6fba5cc2407ea66a69069dd30b3878ff035a8c

Contents?: true

Size: 1.17 KB

Versions: 19

Compression:

Stored size: 1.17 KB

Contents

module NulogyMessageBusProducer
  module Subscriptions
    # Query Analyzer that returns an error when a subscription field
    # has variables. See `SUBSCRIPTION_WITH_VARIABLES_MESSAGE`.
    class NoVariables < GraphQL::Analysis::AST::Analyzer
      SUBSCRIPTION_WITH_VARIABLES_MESSAGE = <<~MESSAGE.freeze
        Subscriptions should not be created with arguments. e.g.

        subscription($id: ID!) { fooWasCreated(id: $id) { ... } }
        with variables { id: id_value, ... }

        the $id variable should be inlined into the event that they are subscribing to:

        subscription { fooWasCreated(id: id_value) { ... } }
      MESSAGE

      def initialize(query_or_multiplex)
        super
        @error = false
      end

      def analyze?
        subject.subscription?
      end

      def on_enter_operation_definition(node, _parent, _visitor)
        @error = true if subscription?(node) && node.variables.present?
      end

      def result
        return unless @error

        GraphQL::AnalysisError.new(SUBSCRIPTION_WITH_VARIABLES_MESSAGE)
      end

      private

      def subscription?(node)
        node.operation_type == "subscription"
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
nulogy_message_bus_producer-5.0.8 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-5.0.7 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-5.0.6 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-5.0.5 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-5.0.4 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-5.0.3 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-5.0.2 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-5.0.1 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-5.0.1.alpha lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-5.0.0 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-4.0.0 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-3.7.0 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-3.6.0 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-3.5.0 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-4.0.0.alpha lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-3.4.1 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-3.4.0 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-3.3.0 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
nulogy_message_bus_producer-3.2.1 lib/nulogy_message_bus_producer/subscriptions/no_variables.rb