graphql-fragment_cache 1.14.0 → 1.15.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: 44be1de2fded16cfd021afebe96ce647616225fdbe5de8b140099d2c1bb16f94
4
- data.tar.gz: 94fb9a82b527c9786d81fed29e821416038c0b20a63f33fe765fc76abf0a9c24
3
+ metadata.gz: ba042028d0f9a6b8baebcfd86fcfddf9eb571014967498e1f0f609ad6445da18
4
+ data.tar.gz: ccf1d4764c9178faceac2ef63dbeb30ba7b1a303dbfc5e299289be3ec56a9ddd
5
5
  SHA512:
6
- metadata.gz: c10be9f09dcddd09f175452f86071330fe3cb72e9d5875169e20c000372a88ec44e9c9830154e5d2016af177e55852ccf3ae2594e5069e939be4ab0a43676a24
7
- data.tar.gz: 5ded87b46c9757d28ac95028d16f2e2e71c3ed3d5252285898cc033dff835e61bff6aa7777633b8798eed6fb9dcecacf78d0e0623f1952f74139be8b66a9beee
6
+ metadata.gz: 6025cf472c24989b66d47b3d7c79d6d5a5bdb8e71540c0e7c0ca7bc2bd2baf5b438206e978d1d4d5bbdd975e793e675d5370364ece2f8ca223aa4eabed263c9e
7
+ data.tar.gz: 80e93356549005e70a9e3e66a6d87716aebcfc3a3b540e91ffb935d4fb18533df56164664a78c9371c69d07197e92be3aabfd54916428b94cdd19b7952e0d18a
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.15.0 (2022-10-27)
6
+
7
+ - [PR#43](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/43) Implement `skip_cache_when_query_has_errors` option to skip caching when query was resolved with errors ([@DmitryTsepelev][])
8
+
5
9
  ## 1.14.0 (2022-10-26)
6
10
 
7
11
  - [PR#85](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/85) Support passing Symbols to `if:` and `unless:` ([@palkan][])
data/README.md CHANGED
@@ -424,6 +424,16 @@ end
424
424
 
425
425
  This can reduce a number of cache calls but _increase_ memory usage, because the value returned from cache will be kept in the GraphQL context until the query is fully resolved.
426
426
 
427
+ ## Execution errors and caching
428
+
429
+ Sometimes errors happen during query resolving and it might make sense to skip caching for such queries (for instance, imagine a situation when client has no access to the requested field and the backend returns `{ data: {}, errors: ["you need a permission to fetch orders"] }`). This is how this behavior can be turned on (_it's off by default!_):
430
+
431
+ ```ruby
432
+ GraphQL::FragmentCache.skip_cache_when_query_has_errors = true
433
+ ```
434
+
435
+ As a result, caching will be skipped when `errors` array is not empty.
436
+
427
437
  ## Limitations
428
438
 
429
439
  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:
@@ -13,10 +13,15 @@ module GraphQL
13
13
  end
14
14
 
15
15
  def after_query(query)
16
- return unless query.valid?
16
+ return if skip_caching?(query)
17
17
 
18
18
  Cacher.call(query)
19
19
  end
20
+
21
+ def skip_caching?(query)
22
+ !query.valid? ||
23
+ GraphQL::FragmentCache.skip_cache_when_query_has_errors? && query.context.errors.any?
24
+ end
20
25
  end
21
26
  end
22
27
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module FragmentCache
5
- VERSION = "1.14.0"
5
+ VERSION = "1.15.0"
6
6
  end
7
7
  end
@@ -25,6 +25,8 @@ module GraphQL
25
25
  attr_accessor :namespace
26
26
  attr_accessor :default_options
27
27
 
28
+ attr_accessor :skip_cache_when_query_has_errors
29
+
28
30
  def use(schema_defn, options = {})
29
31
  verify_interpreter_and_analysis!(schema_defn)
30
32
 
@@ -52,6 +54,8 @@ module GraphQL
52
54
  @cache_store = store
53
55
  end
54
56
 
57
+ alias skip_cache_when_query_has_errors? skip_cache_when_query_has_errors
58
+
55
59
  def graphql_ruby_before_2_0?
56
60
  check_graphql_version "< 2.0.0"
57
61
  end
@@ -84,6 +88,7 @@ module GraphQL
84
88
 
85
89
  self.cache_store = MemoryStore.new
86
90
  self.default_options = {}
91
+ self.skip_cache_when_query_has_errors = false
87
92
  end
88
93
  end
89
94
 
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.14.0
4
+ version: 1.15.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-26 00:00:00.000000000 Z
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql