Class: GraphQL::ResultCache::ContextConfig
- Inherits:
-
Object
- Object
- GraphQL::ResultCache::ContextConfig
- Defined in:
- lib/graphql/result_cache/context_config.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #add(context:, key:, after_process: nil) ⇒ Object
-
#initialize ⇒ ContextConfig
constructor
A new instance of ContextConfig.
- #of_query(query) ⇒ Object
- #process(result) ⇒ Object
Constructor Details
#initialize ⇒ ContextConfig
Returns a new instance of ContextConfig.
7 8 9 |
# File 'lib/graphql/result_cache/context_config.rb', line 7 def initialize @value = {} end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/graphql/result_cache/context_config.rb', line 5 def value @value end |
Instance Method Details
#add(context:, key:, after_process: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/graphql/result_cache/context_config.rb', line 11 def add context:, key:, after_process: nil @value[context.query] ||= [] cached = cache.exist? key logger&.info "GraphQL result cache key #{cached ? 'hit' : 'miss'}: #{key}" config_value = { path: context.path, key: key } if cached config_value[:result] = cache.read(key) config_value[:after_process] = after_process if after_process end @value[context.query] << config_value cached end |
#of_query(query) ⇒ Object
29 30 31 |
# File 'lib/graphql/result_cache/context_config.rb', line 29 def of_query query @value[query] end |
#process(result) ⇒ Object
24 25 26 27 |
# File 'lib/graphql/result_cache/context_config.rb', line 24 def process result config_of_query = of_query(result.query) blank?(config_of_query) ? result : cache_or_amend_result(result, config_of_query) end |