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.



133
134
135
136
137
138
139
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 133

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.



131
132
133
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 131

def object
  @object
end

#pathObject (readonly)

Returns the value of attribute path.



131
132
133
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 131

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



131
132
133
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 131

def query
  @query
end

#schemaObject (readonly)

Returns the value of attribute schema.



131
132
133
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 131

def schema
  @schema
end

Class Method Details

.call(**options) ⇒ Object



126
127
128
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 126

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

Instance Method Details

#buildObject



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 141

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



216
217
218
# File 'lib/graphql/fragment_cache/cache_key_builder.rb', line 216

def object_key(obj)
  obj&._graphql_cache_key
end