Sha256: aed73f32aa324fc21893609e33413635cf4dcfb7b82d4974455574ed1d1accc2

Contents?: true

Size: 1.86 KB

Versions: 16

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true
module GraphQL
  module Analysis
    module AST
      # Query analyzer for query ASTs. Query analyzers respond to visitor style methods
      # but are prefixed by `enter` and `leave`.
      #
      # @param [GraphQL::Query] The query to analyze
      class Analyzer
        def initialize(query)
          @query = query
        end

        # Analyzer hook to decide at analysis time whether a query should
        # be analyzed or not.
        # @return [Boolean] If the query should be analyzed or not
        def analyze?
          true
        end

        # The result for this analyzer. Returning {GraphQL::AnalysisError} results
        # in a query error.
        # @return [Any] The analyzer result
        def result
          raise NotImplementedError
        end

        # Don't use make_visit_method because it breaks `super`
        def self.build_visitor_hooks(member_name)
          class_eval(<<-EOS, __FILE__, __LINE__ + 1)
            def on_enter_#{member_name}(node, parent, visitor)
            end

            def on_leave_#{member_name}(node, parent, visitor)
            end
          EOS
        end

        build_visitor_hooks :argument
        build_visitor_hooks :directive
        build_visitor_hooks :document
        build_visitor_hooks :enum
        build_visitor_hooks :field
        build_visitor_hooks :fragment_spread
        build_visitor_hooks :inline_fragment
        build_visitor_hooks :input_object
        build_visitor_hooks :list_type
        build_visitor_hooks :non_null_type
        build_visitor_hooks :null_value
        build_visitor_hooks :operation_definition
        build_visitor_hooks :type_name
        build_visitor_hooks :variable_definition
        build_visitor_hooks :variable_identifier
        build_visitor_hooks :abstract_node

        protected

        attr_reader :query
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
graphql-1.9.12 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.11 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.10 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.9 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.8 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.7 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.6 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.5 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.4 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.3 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.2 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.1 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.0 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.0.pre4 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.0.pre3 lib/graphql/analysis/ast/analyzer.rb
graphql-1.9.0.pre2 lib/graphql/analysis/ast/analyzer.rb