Module: GraphQL::Analysis
- Defined in:
- lib/graphql/analysis/ast.rb,
lib/graphql/analysis/ast/visitor.rb,
lib/graphql/analysis/field_usage.rb,
lib/graphql/analysis/query_depth.rb,
lib/graphql/analysis/ast/analyzer.rb,
lib/graphql/analysis/analyze_query.rb,
lib/graphql/analysis/reducer_state.rb,
lib/graphql/analysis/ast/field_usage.rb,
lib/graphql/analysis/ast/query_depth.rb,
lib/graphql/analysis/max_query_depth.rb,
lib/graphql/analysis/query_complexity.rb,
lib/graphql/analysis/ast/max_query_depth.rb,
lib/graphql/analysis/ast/query_complexity.rb,
lib/graphql/analysis/max_query_complexity.rb,
lib/graphql/analysis/ast/max_query_complexity.rb
Defined Under Namespace
Modules: AST Classes: FieldUsage, MaxQueryComplexity, MaxQueryDepth, QueryComplexity, QueryDepth, ReducerState
Class Method Summary collapse
-
.analyze_multiplex(multiplex, analyzers) ⇒ void
-
.analyze_query(query, analyzers, multiplex_states: []) ⇒ Array<Any>
Visit
query
’s internal representation, callinganalyzers
along the way. -
.use(schema_class) ⇒ Object
Class Method Details
.analyze_multiplex(multiplex, analyzers) ⇒ void
This method returns an undefined value.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/graphql/analysis/analyze_query.rb', line 12 def analyze_multiplex(multiplex, analyzers) multiplex.trace("analyze_multiplex", { multiplex: multiplex }) do reducer_states = analyzers.map { |r| ReducerState.new(r, multiplex) } query_results = multiplex.queries.map do |query| if query.valid? analyze_query(query, query.analyzers, multiplex_states: reducer_states) else [] end end multiplex_results = reducer_states.map(&:finalize_reducer) multiplex_errors = analysis_errors(multiplex_results) multiplex.queries.each_with_index do |query, idx| query.analysis_errors = multiplex_errors + analysis_errors(query_results[idx]) end end nil end |
.analyze_query(query, analyzers, multiplex_states: []) ⇒ Array<Any>
Visit query
’s internal representation, calling analyzers
along the way.
- First, query analyzers are filtered down by calling
.analyze?(query)
, if they respond to that method - Then, query analyzers are initialized by calling
.initial_value(query)
, if they respond to that method. - Then, they receive
.call(memo, visit_type, irep_node)
, where visit type is:enter
or:leave
. - Last, they receive
.final_value(memo)
, if they respond to that method.
It returns an array of final memo
values in the order that analyzers
were passed in.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/graphql/analysis/analyze_query.rb', line 45 def analyze_query(query, analyzers, multiplex_states: []) GraphQL::Deprecation.warn "Legacy analysis will be removed in GraphQL-Ruby 2.0, please upgrade to AST Analysis: https://graphql-ruby.org/queries/ast_analysis.html (schema: #{query.schema})" query.trace("analyze_query", { query: query }) do analyzers_to_run = analyzers.select do |analyzer| if analyzer.respond_to?(:analyze?) analyzer.analyze?(query) else true end end reducer_states = analyzers_to_run.map { |r| ReducerState.new(r, query) } + multiplex_states irep = query.internal_representation irep.operation_definitions.each do |name, op_node| reduce_node(op_node, reducer_states) end reducer_states.map(&:finalize_reducer) end end |
.use(schema_class) ⇒ Object
6 7 8 9 |
# File 'lib/graphql/analysis/analyze_query.rb', line 6 def use(schema_class) schema = schema_class.is_a?(Class) ? schema_class : schema_class.target schema.analysis_engine = self end |