Skip to content

Commit 91a5c9b

Browse files
authored
Fix warning on ActiveSupport::Cache.format_version
`Rail.application` was always evaluating to `nil` before as the code wasn't running in an initializer. Also make sure that `cache_format_version` is only rewritten in test environment and ONLY if it'd raise a warning otherwise (and shift it back to the previous value after the cache store is initialized). This should prevent the warning while also having minimal impact out of the test environment.
1 parent 5878078 commit 91a5c9b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/graphql/fragment_cache/railtie.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ class Railtie < ::Rails::Railtie # :nodoc:
1010
module Config
1111
class << self
1212
def store=(store)
13-
if Rails.version.to_f >= 7.0 && Rails.application
14-
cache_format_version = 7.0
15-
ActiveSupport::Cache.format_version = cache_format_version if cache_format_version
16-
end
17-
1813
# Handle both:
1914
# store = :memory
2015
# store = :mem_cache, ENV['MEMCACHE']
@@ -30,7 +25,14 @@ def store=(store)
3025
config.graphql_fragment_cache = Config
3126

3227
if ENV["RACK_ENV"] == "test" || ENV["RAILS_ENV"] == "test"
33-
config.graphql_fragment_cache.store = :null_store
28+
initializer 'graphql-fragment_cache' do
29+
if Rails.version.to_f >= 7.0 && ::ActiveSupport::Cache.format_version < 7.0
30+
cache_format_version = ::ActiveSupport::Cache.format_version
31+
::ActiveSupport::Cache.format_version = 7.0
32+
config.graphql_fragment_cache.store = :null_store
33+
::ActiveSupport::Cache.format_version = cache_format_version
34+
end
35+
end
3436
end
3537
end
3638
end

0 commit comments

Comments
 (0)