Class: Rails::GraphQL::Request::Strategy::CachedStrategy
- Inherits:
-
Rails::GraphQL::Request::Strategy
- Object
- Rails::GraphQL::Request::Strategy
- Rails::GraphQL::Request::Strategy::CachedStrategy
- Defined in:
- lib/rails/graphql/request/strategy/cached_strategy.rb
Overview
GraphQl Cached Strategy
This strategy will process hard cached operations. Soft cached operations are those that only the document is cached in the server and processed via its unique identifier (UUID). Whereas, hard cached operations pretty muchy skips the organize step since that is what is cached.
Beware, if the version in the cache is different from the version in the type map, it won’t be able to process it.
Constant Summary
Constants inherited from Rails::GraphQL::Request::Strategy
Instance Attribute Summary
Attributes inherited from Rails::GraphQL::Request::Strategy
#context, #listeners, #request, #stage
Class Method Summary collapse
-
.can_resolve?(request) ⇒ Boolean
Resolve whenever it has a cache directive on any of the operations.
Instance Method Summary collapse
-
#resolve! ⇒ Object
Executes the strategy in the normal mode.
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
Resolve whenever it has a cache directive on any of the operations
22 23 24 25 26 27 |
# File 'lib/rails/graphql/request/strategy/cached_strategy.rb', line 22 def can_resolve?(request) false # request.operations.each_value.any? do |op| # op.data&.directives&.any? { |dir| directive_name(dir) == 'cached' } # end end |
Instance Method Details
#resolve! ⇒ Object
Executes the strategy in the normal mode
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rails/graphql/request/strategy/cached_strategy.rb', line 37 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! } } # collect_data(true) { op.prepare! } # collect_response { op.resolve! } # operations.each_value do |op| # collect_listeners { op.organize! } # collect_data(true) { op.prepare! } # collect_response { op.resolve! } # end end end |