graphiti 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1153a7480fa50066880ae8fd1b5a4f99a24e69ae3ebffb40ae114dbfcffc9910
4
- data.tar.gz: 0f3836b75fb3db4a88393d1ec7877340dedea40e9c59350a8e30f1f4ebce10f1
3
+ metadata.gz: ad1f5708fdf6d0ce3e322a050c23440765c7d965be7020e1c1fa1a4a8205ee85
4
+ data.tar.gz: b80f90e0cc2421b89ef4ccbb142bb8ee67ccb5490eb55ace716ca22e154cc578
5
5
  SHA512:
6
- metadata.gz: 7e62b853539691e1649da7ff41441f75e5726af05ee88de6d0721b909926733162c07eeb82763dfc0bbc19ea953026ebd5ab2acf03e11313a7d584894dc89263
7
- data.tar.gz: 046642e0a06b2340054d501ace62e56c42cb1ab66c3f1939c05fc59b9b14107109276848e2204eb4b6b18378ab3c4ba18ca45cd8025e54036e413f7079943068
6
+ metadata.gz: 9f2a223141a825552d578c2b3720a2157337e48ff7a4c3bb55b09eb3dac0093f65903c20b048893b8ab61ea47cc21c61c41a25ae59aa2163efe08c721e5dd5b8
7
+ data.tar.gz: 4bb15d52b3749de416d8c90cf6e9964614412346ed25e9504135da48b187d5212aa6c79931e8c4ff1691cc83bea439f12d3d2813736c23bc80afbb9c8082ee6c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  graphiti changelog
2
2
 
3
+ # [1.10.0](https://github.com/graphiti-api/graphiti/compare/v1.9.0...v1.10.0) (2026-01-06)
4
+
5
+
6
+ ### Features
7
+
8
+ * add cache tag support to allow context-aware caching ([#498](https://github.com/graphiti-api/graphiti/issues/498)) ([e8c2bad](https://github.com/graphiti-api/graphiti/commit/e8c2bad478cb3dd8dbd1a5e993b10f84046a0fa8))
9
+
3
10
  # [1.9.0](https://github.com/graphiti-api/graphiti/compare/v1.8.2...v1.9.0) (2026-01-03)
4
11
 
5
12
 
@@ -4,9 +4,10 @@ module Graphiti
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  class_methods do
7
- def cache_resource(expires_in: false)
7
+ def cache_resource(expires_in: false, tag: nil)
8
8
  @cache_resource = true
9
9
  @cache_expires_in = expires_in
10
+ @cache_tag = tag
10
11
  end
11
12
 
12
13
  def all(params = {}, base_scope = nil)
@@ -55,7 +56,7 @@ module Graphiti
55
56
  private
56
57
 
57
58
  def caching_options
58
- {cache: @cache_resource, cache_expires_in: @cache_expires_in}
59
+ {cache: @cache_resource, cache_expires_in: @cache_expires_in, cache_tag: @cache_tag}
59
60
  end
60
61
 
61
62
  def validate_request!(params)
@@ -2,14 +2,19 @@ module Graphiti
2
2
  class ResourceProxy
3
3
  include Enumerable
4
4
 
5
- attr_reader :resource, :query, :scope, :payload, :cache_expires_in, :cache
5
+ attr_reader :resource, :query, :scope, :payload, :cache_expires_in, :cache, :cache_tag
6
6
 
7
- def initialize(resource, scope, query,
7
+ def initialize(
8
+ resource,
9
+ scope,
10
+ query,
8
11
  payload: nil,
9
12
  single: false,
10
13
  raise_on_missing: false,
11
14
  cache: nil,
12
- cache_expires_in: nil)
15
+ cache_expires_in: nil,
16
+ cache_tag: nil
17
+ )
13
18
 
14
19
  @resource = resource
15
20
  @scope = scope
@@ -19,6 +24,7 @@ module Graphiti
19
24
  @raise_on_missing = raise_on_missing
20
25
  @cache = cache
21
26
  @cache_expires_in = cache_expires_in
27
+ @cache_tag = cache_tag
22
28
  end
23
29
 
24
30
  def cache?
@@ -207,12 +213,30 @@ module Graphiti
207
213
  "W/#{ActiveSupport::Digest.hexdigest(cache_key_with_version.to_s)}"
208
214
  end
209
215
 
216
+ def resource_cache_tag
217
+ return unless @cache_tag.present? && @resource.respond_to?(@cache_tag)
218
+
219
+ @resource.try(@cache_tag)
220
+ end
221
+
210
222
  def cache_key
211
- ActiveSupport::Cache.expand_cache_key([@scope.cache_key, @query.cache_key])
223
+ ActiveSupport::Cache.expand_cache_key(
224
+ [
225
+ @scope.cache_key,
226
+ @query.cache_key,
227
+ resource_cache_tag
228
+ ].compact_blank
229
+ )
212
230
  end
213
231
 
214
232
  def cache_key_with_version
215
- ActiveSupport::Cache.expand_cache_key([@scope.cache_key_with_version, @query.cache_key])
233
+ ActiveSupport::Cache.expand_cache_key(
234
+ [
235
+ @scope.cache_key_with_version,
236
+ @query.cache_key,
237
+ resource_cache_tag
238
+ ].compact_blank
239
+ )
216
240
  end
217
241
 
218
242
  private
@@ -58,22 +58,29 @@ module Graphiti
58
58
 
59
59
  def proxy(base = nil, opts = {})
60
60
  base ||= jsonapi_resource.base_scope
61
- scope_opts = opts.slice :sideload_parent_length,
61
+ scope_opts = opts.slice(
62
+ :sideload_parent_length,
62
63
  :default_paginate,
63
64
  :after_resolve,
64
65
  :sideload,
65
66
  :parent,
66
67
  :params,
67
68
  :bypass_required_filters
69
+ )
70
+
68
71
  scope = jsonapi_scope(base, scope_opts)
69
- ResourceProxy.new jsonapi_resource,
72
+
73
+ ::Graphiti::ResourceProxy.new(
74
+ jsonapi_resource,
70
75
  scope,
71
76
  query,
72
77
  payload: deserialized_payload,
73
78
  single: opts[:single],
74
79
  raise_on_missing: opts[:raise_on_missing],
75
80
  cache: opts[:cache],
76
- cache_expires_in: opts[:cache_expires_in]
81
+ cache_expires_in: opts[:cache_expires_in],
82
+ cache_tag: opts[:cache_tag]
83
+ )
77
84
  end
78
85
  end
79
86
  end
@@ -12,7 +12,9 @@ module Graphiti
12
12
  end
13
13
 
14
14
  def name
15
- "#{Graphiti.context[:object]&.request&.method} #{Graphiti.context[:object]&.request&.url}"
15
+ tag = proxy.resource_cache_tag
16
+
17
+ "#{::Graphiti.context[:object]&.request&.method} #{::Graphiti.context[:object]&.request&.url} #{tag}"
16
18
  end
17
19
 
18
20
  def key
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.9.0"
2
+ VERSION = "1.10.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-03 00:00:00.000000000 Z
11
+ date: 2026-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable