Class: Rails::GraphQL::Request::Strategy::MultiQueryStrategy

Inherits:
Rails::GraphQL::Request::Strategy show all
Defined in:
lib/rails/graphql/request/strategy/multi_query_strategy.rb

Overview

GraphQl Multi Query Strategy

This is a resolution strategy to solve requests that only contain queries, allowing the strategy to collect all the information for all the queries in a single step before resolving it.

Constant Summary

Constants inherited from Rails::GraphQL::Request::Strategy

PREPARE_XARGS

Instance Attribute Summary

Attributes inherited from Rails::GraphQL::Request::Strategy

#context, #listeners, #request, #stage

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rails::GraphQL::Request::Strategy

#add_listeners_from, #cache_dump, #cache_load, #clear, #compile, #find_directive!, #find_type!, #initialize, #instance_for, #listeners?, #listening_to?, #perform, #prepare, #prepared_data_for, #resolve, #resolve_data_for, #safe_store_data, #stacked, #store_data, #trigger_event

Constructor Details

This class inherits a constructor from Rails::GraphQL::Request::Strategy

Class Method Details

.can_resolve?(request) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rails/graphql/request/strategy/multi_query_strategy.rb', line 14

def self.can_resolve?(request)
  request.operations.each_value.all? { |op| op.of_type?(:query) }
end

Instance Method Details

#resolve!Object

Executes the strategy in the normal mode



19
20
21
22
23
24
25
# File 'lib/rails/graphql/request/strategy/multi_query_strategy.rb', line 19

def resolve!
  response.with_stack('data') do
    for_each_operation { |op| collect_listeners { op.organize! } }
    for_each_operation { |op| collect_data      { op.prepare!  } }
    for_each_operation { |op| collect_response  { op.resolve!  } }
  end
end