Class: GraphQL::Analysis::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/analysis/analyzer.rb

Overview

Query analyzer for query ASTs. Query analyzers respond to visitor style methods but are prefixed by enter and leave.

When an analyzer is initialized with a Multiplex, you can always get the current query from visitor.query in the visit methods.

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ Analyzer

Returns a new instance of Analyzer.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/graphql/analysis/analyzer.rb', line 12

def initialize(subject)
  @subject = subject

  if subject.is_a?(GraphQL::Query)
    @query = subject
    @multiplex = nil
  else
    @multiplex = subject
    @query = nil
  end
end

Instance Method Details

#analyze?Boolean

Analyzer hook to decide at analysis time whether a query should be analyzed or not.

Returns:

  • (Boolean)

    If the query should be analyzed or not



27
28
29
# File 'lib/graphql/analysis/analyzer.rb', line 27

def analyze?
  true
end

#resultAny

The result for this analyzer. Returning GraphQL::AnalysisError results in a query error.

Returns:

  • (Any)

    The analyzer result

Raises:



41
42
43
# File 'lib/graphql/analysis/analyzer.rb', line 41

def result
  raise GraphQL::RequiredImplementationMissingError
end

#visit?Boolean

Analyzer hook to decide at analysis time whether analysis requires a visitor pass; can be disabled for precomputed results.

Returns:

  • (Boolean)

    If analysis requires visitation or not



34
35
36
# File 'lib/graphql/analysis/analyzer.rb', line 34

def visit?
  true
end