You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,49 @@
2
2
3
3
## master
4
4
5
+
## 1.22.0 (2025-02-20)
6
+
7
+
-[PR#134](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/134) Add possibility to include and exclude arguments from generated cache key ([@mgruner][])
8
+
9
+
## 1.21.0 (2025-02-01)
10
+
11
+
-[PR#130](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/130) Dataloader support ([@DmitryTsepelev][])
-[PR#117](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/117) Deprecate old ruby and gql versions ([@DmitryTsepelev][])
25
+
-[PR#116](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/116) Migrate CompiledQueries instrumentation to tracer ([@DmitryTsepelev][])
26
+
27
+
## 1.20.2 (2024-06-01)
28
+
29
+
-[PR#115](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/115) Fix deprecation warning for cache_format_version in Rails 7.1 ([@rince][])
-[PR#109](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/109) Remove `Lookahead` patch in modern versions of graphql-ruby ([@DmitryTsepelev][])
35
+
36
+
## 1.20.0 (2024-03-02)
37
+
38
+
-[PR#108](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/108) Use trace_with instead of deprecated instrument method ([@camero2734][])
39
+
40
+
## 1.19.0 (2023-11-03)
41
+
42
+
-[PR#104](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/104) Support graphql-ruby 2.1.4 ([@DmitryTsepelev][])
43
+
44
+
## 1.18.2 (2023-02-21)
45
+
46
+
-[PR#100](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/100) Fix an error when `path_cache_key` is nil ([@rince][])
47
+
5
48
## 1.18.1 (2023-01-06)
6
49
7
50
-[PR#96](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/96) Properly pass arguments to `write_multi` ([@DmitryTsepelev][])
Likewise, you can use `cache_key: { include_arguments: […] }` to specify an allowlist of arguments
175
+
to be included in the cache key. In this case all arguments for the cache key must be specified, including
176
+
parent arguments of nested fields.
177
+
148
178
### User-provided cache key (custom key)
149
179
150
180
In most cases you want your cache key to depend on the resolved object (say, `ActiveRecord` model). You can do that by passing an argument to the `#cache_fragment` method in a similar way to Rails views [`#cache` method](https://guides.rubyonrails.org/caching_with_rails.html#fragment-caching):
@@ -379,6 +409,34 @@ class QueryType < BaseObject
379
409
end
380
410
```
381
411
412
+
## Dataloader
413
+
414
+
If you are using [Dataloader](https://graphql-ruby.org/dataloader/overview.html), you will need to let the gem know using `dataloader: true`:
The problem is that I didn't find a way to detect that dataloader (and, therefore, Fiber) is used, and the block is forced to resolve, causing the N+1 inside the Dataloader Source class.
439
+
382
440
## How to use `#cache_fragment` in extensions (and other places where context is not available)
383
441
384
442
If you want to call `#cache_fragment` from places other that fields or resolvers, you'll need to pass `context` explicitly and turn on `raw_value` support. For instance, let's take a look at this extension:
@@ -444,6 +502,30 @@ Cache processing can be disabled if needed. For example:
It may be useful to capture cache lookup events. When monitoring is enabled, the `cache_key`, `operation_name`, `path` and a boolean indicating a cache hit or miss will be sent to a `cache_lookup_event` method. This method can be implemented in your application to handle the event.
508
+
509
+
Example handler defined in a Rails initializer:
510
+
511
+
```ruby
512
+
moduleGraphQL
513
+
moduleFragmentCache
514
+
classFragment
515
+
defself.cache_lookup_event(**args)
516
+
# Monitoring such as incrementing a cache hit counter metric
517
+
end
518
+
end
519
+
end
520
+
end
521
+
```
522
+
523
+
Like managing caching itself, monitoring can be enabled if needed. It is disabled by default. For example:
524
+
525
+
```ruby
526
+
GraphQL::FragmentCache.monitoring_enabled =true
527
+
```
528
+
447
529
## Limitations
448
530
449
531
1.`Schema#execute`, [graphql-batch](https://github.com/Shopify/graphql-batch) and _graphql-ruby-fragment_cache_ do not [play well](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/issues/45) together. The problem appears when `cache_fragment` is _inside_ the `.then` block:
2. Caching does not work for Union types, because of the `Lookahead` implementation: it requires the exact type to be passed to the `selection` method (you can find the [discussion](https://github.com/rmosolgo/graphql-ruby/pull/3007) here). This method is used for cache key building, and I haven't found a workaround yet ([PR in progress](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/30)). If you get `Failed to look ahead the field` error — please pass `query_cache_key` explicitly:
554
+
2. Caching does not work for Union types, because of the `Lookahead` implementation: it requires the exact type to be passed to the `selection` method (you can find the [discussion](https://github.com/rmosolgo/graphql-ruby/pull/3007) here). This method is used for cache key building, and I haven't found a workaround yet ([PR in progress](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/30)). If you get `Failed to look ahead the field` error — please pass `path_cache_key` explicitly:
0 commit comments