graphql-fragment_cache 1.13.1 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +6 -0
- data/lib/graphql/fragment_cache/field_extension.rb +20 -4
- data/lib/graphql/fragment_cache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44be1de2fded16cfd021afebe96ce647616225fdbe5de8b140099d2c1bb16f94
|
4
|
+
data.tar.gz: 94fb9a82b527c9786d81fed29e821416038c0b20a63f33fe765fc76abf0a9c24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c10be9f09dcddd09f175452f86071330fe3cb72e9d5875169e20c000372a88ec44e9c9830154e5d2016af177e55852ccf3ae2594e5069e939be4ab0a43676a24
|
7
|
+
data.tar.gz: 5ded87b46c9757d28ac95028d16f2e2e71c3ed3d5252285898cc033dff835e61bff6aa7777633b8798eed6fb9dcecacf78d0e0623f1952f74139be8b66a9beee
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.14.0 (2022-10-26)
|
6
|
+
|
7
|
+
- [PR#85](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/85) Support passing Symbols to `if:` and `unless:` ([@palkan][])
|
8
|
+
|
9
|
+
- [PR#85](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/85) Fix conditional caching ([@palkan][])
|
10
|
+
|
5
11
|
## 1.13.1 (2022-10-12)
|
6
12
|
|
7
13
|
- [PR#84](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/84) Fix Renew Cache Read Multi Bug ([@KTSCode][])
|
data/README.md
CHANGED
@@ -300,6 +300,12 @@ end
|
|
300
300
|
field :post, PostType, cache_fragment: {if: -> { current_user.nil? }} do
|
301
301
|
argument :id, ID, required: true
|
302
302
|
end
|
303
|
+
|
304
|
+
# or
|
305
|
+
|
306
|
+
field :post, PostType, cache_fragment: {if: :current_user?} do
|
307
|
+
argument :id, ID, required: true
|
308
|
+
end
|
303
309
|
```
|
304
310
|
|
305
311
|
## Default options
|
@@ -35,6 +35,12 @@ module GraphQL
|
|
35
35
|
|
36
36
|
@context_key = @cache_options.delete(:context_key)
|
37
37
|
@cache_key = @cache_options.delete(:cache_key)
|
38
|
+
|
39
|
+
@if = @cache_options.delete(:if)
|
40
|
+
@unless = @cache_options.delete(:unless)
|
41
|
+
|
42
|
+
# Make sure we do not modify options, since they're global
|
43
|
+
@cache_options.freeze
|
38
44
|
end
|
39
45
|
|
40
46
|
NOT_RESOLVED = Object.new
|
@@ -42,11 +48,20 @@ module GraphQL
|
|
42
48
|
def resolve(object:, arguments:, **_options)
|
43
49
|
resolved_value = NOT_RESOLVED
|
44
50
|
|
45
|
-
if @
|
46
|
-
|
51
|
+
if @if.is_a?(Proc) && !object.instance_exec(&@if)
|
52
|
+
return yield(object, arguments)
|
53
|
+
end
|
54
|
+
|
55
|
+
if @if.is_a?(Symbol) && !object.send(@if)
|
56
|
+
return yield(object, arguments)
|
47
57
|
end
|
48
|
-
|
49
|
-
|
58
|
+
|
59
|
+
if @unless.is_a?(Proc) && object.instance_exec(&@unless)
|
60
|
+
return yield(object, arguments)
|
61
|
+
end
|
62
|
+
|
63
|
+
if @unless.is_a?(Symbol) && object.send(@unless)
|
64
|
+
return yield(object, arguments)
|
50
65
|
end
|
51
66
|
|
52
67
|
object_for_key = if @context_key
|
@@ -56,6 +71,7 @@ module GraphQL
|
|
56
71
|
elsif @cache_key == :value
|
57
72
|
resolved_value = yield(object, arguments)
|
58
73
|
end
|
74
|
+
|
59
75
|
cache_fragment_options = @cache_options.merge(object: object_for_key)
|
60
76
|
|
61
77
|
object.cache_fragment(**cache_fragment_options) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-fragment_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|