Class: GraphQL::FragmentCache::CacheKeyBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/fragment_cache/cache_key_builder.rb,
lib/graphql/fragment_cache/rails/cache_key_builder.rb

Overview

Extends key builder to use .expand_cache_key in Rails

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, path:, object: nil, **options) ⇒ CacheKeyBuilder

Returns a new instance of CacheKeyBuilder.



66
67
68
69
70
71
72
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 66

def initialize(query:, path:, object: nil, **options)
  @object = object
  @query = query
  @schema = query.schema
  @path = path
  @options = options
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



64
65
66
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 64

def object
  @object
end

#pathObject (readonly)

Returns the value of attribute path.



64
65
66
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 64

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



64
65
66
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 64

def query
  @query
end

#schemaObject (readonly)

Returns the value of attribute schema.



64
65
66
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 64

def schema
  @schema
end

Class Method Details

.call(**options) ⇒ Object



59
60
61
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 59

def call(**options)
  new(**options).build
end

Instance Method Details

#buildObject



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 74

def build
  key_parts = [
    GraphQL::FragmentCache.namespace,
    simple_path_cache_key,
    implicit_cache_key,
    object_cache_key
  ]

  key_parts
    .compact
    .map { |key_part| key_part.tr("/", "-") }
    .join("/")
end

#object_key(obj) ⇒ Object



159
160
161
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 159

def object_key(obj)
  obj&._graphql_cache_key
end