Class: GraphQL::Cache::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/cache/middleware.rb

Overview

graphql-ruby middleware to wrap resolvers for caching

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_type, parent_object, field_definition, field_args, query_context) ⇒ Middleware

Returns a new instance of Middleware.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/graphql/cache/middleware.rb', line 15

def initialize(parent_type,
               parent_object,
               field_definition,
               field_args,
               query_context)
  self.parent_type      = parent_type
  self.parent_object    = parent_object
  self.field_definition = field_definition
  self.field_args       = field_args
  self.query_context    = query_context
  self.cache            = ::GraphQL::Cache.cache

  return unless parent_object

  self.object = parent_object.nodes if parent_object.respond_to? :nodes
  self.object = parent_object.object if parent_object.respond_to? :object
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



7
8
9
# File 'lib/graphql/cache/middleware.rb', line 7

def cache
  @cache
end

#field_argsObject

Returns the value of attribute field_args.



7
8
9
# File 'lib/graphql/cache/middleware.rb', line 7

def field_args
  @field_args
end

#field_definitionObject

Returns the value of attribute field_definition.



7
8
9
# File 'lib/graphql/cache/middleware.rb', line 7

def field_definition
  @field_definition
end

#objectObject

Returns the value of attribute object.



7
8
9
# File 'lib/graphql/cache/middleware.rb', line 7

def object
  @object
end

#parent_objectObject

Returns the value of attribute parent_object.



7
8
9
# File 'lib/graphql/cache/middleware.rb', line 7

def parent_object
  @parent_object
end

#parent_typeObject

Returns the value of attribute parent_type.



7
8
9
# File 'lib/graphql/cache/middleware.rb', line 7

def parent_type
  @parent_type
end

#query_contextObject

Returns the value of attribute query_context.



7
8
9
# File 'lib/graphql/cache/middleware.rb', line 7

def query_context
  @query_context
end

Class Method Details

.call(*args, &block) ⇒ Object

Called by graphql-ruby during middleware processing



11
12
13
# File 'lib/graphql/cache/middleware.rb', line 11

def self.call(*args, &block)
  new(*args).call(&block)
end

Instance Method Details

#call(&block) ⇒ Object

The primary caching entry point

Returns:

  • (Object)


57
58
59
60
61
62
63
# File 'lib/graphql/cache/middleware.rb', line 57

def call(&block)
  GraphQL::Cache.fetch(
    cache_key,
    config: cache_config,
    &block
  )
end