graphql-fragment_cache 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 515ec358aecf867ce2d2ec5ac82003d802dc6c31d6402d62593a626ac5bad81e
4
- data.tar.gz: 8b1b3d82c0fb808a2cd826c710047635ba141895843ff7b804a301848d266ff5
3
+ metadata.gz: 8fd575d2efddb52ef6d0f878b40823baae40cedec5aa683ba5f6a1b39b98bffe
4
+ data.tar.gz: eba1c06d3650d395575bd96927f831fc206f797b47afa9ebfcfff9adbf2ecf1d
5
5
  SHA512:
6
- metadata.gz: 2c2dd089bf31f6d2491fc7d904d8ca356a2dfbc2cace258fe1e3b49c18dc59a64805a1cb96655bfb23eacc62ed027198365491759005b232354a2ee8ed41e605
7
- data.tar.gz: 92309ef8b7ee62a5fd85007a88be932874f996d12ee08a1e81530d90fa3138dc631f90ad6a6f41c3952338001e10cefbeb1691bcea7891ba9b2f4027543e659d
6
+ metadata.gz: 5fe016ab01f8b8076b1cc6680f8a09ad9bf1ab9d7f5c798a308465fd0d6d80dd6da24ef5855aa35660d9b8cce0529ab59cb6a45b7b971c58d4f8a9e761b80ff9
7
+ data.tar.gz: 0430b991c22524be88e3741f700d5c02ac65186f4cf40e7f06440b737c345bba8e44748a9e8d6ef1293356e21ee7560595b5e1563c28da7bb5f88008f7174360
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.0.3 (2020-08-31)
6
+
7
+ - [PR#29](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/29) Cache result JSON instead of connection objects ([@DmitryTsepelev][])
8
+
5
9
  ## 1.0.2 (2020-08-19)
6
10
 
7
11
  - [PR#28](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/28) Support #keys method for GraphQL::FragmentCache::MemoryStore instance ([@reabiliti][])
@@ -6,6 +6,8 @@ require "graphql/fragment_cache/ext/context_fragments"
6
6
  require "graphql/fragment_cache/ext/graphql_cache_key"
7
7
  require "graphql/fragment_cache/object"
8
8
 
9
+ require "graphql/fragment_cache/connections/patch"
10
+
9
11
  require "graphql/fragment_cache/schema/patch"
10
12
  require "graphql/fragment_cache/schema/tracer"
11
13
  require "graphql/fragment_cache/schema/instrumentation"
@@ -26,6 +28,8 @@ module GraphQL
26
28
  schema_defn.tracer(Schema::Tracer)
27
29
  schema_defn.instrument(:query, Schema::Instrumentation)
28
30
  schema_defn.extend(Schema::Patch)
31
+
32
+ GraphQL::Pagination::Connections.prepend(Connections::Patch)
29
33
  end
30
34
 
31
35
  def cache_store=(store)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphQL
4
+ module FragmentCache
5
+ module Connections
6
+ # Patches GraphQL::Pagination::Connections to support raw values
7
+ module Patch
8
+ if Gem::Dependency.new("graphql", ">= 1.11.0").match?("graphql", GraphQL::VERSION)
9
+ def wrap(field, parent, items, arguments, context, *options)
10
+ raw_value?(items) ? items : super
11
+ end
12
+ else
13
+ def wrap(field, object, arguments, context, *options)
14
+ raw_value?(object) ? object : super
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def raw_value?(value)
21
+ GraphQL::Execution::Interpreter::RawValue === value
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -8,8 +8,6 @@ module GraphQL
8
8
  class Fragment
9
9
  attr_reader :options, :path, :context
10
10
 
11
- attr_accessor :resolved_value
12
-
13
11
  def initialize(context, **options)
14
12
  @context = context
15
13
  @options = options
@@ -25,9 +23,7 @@ module GraphQL
25
23
  end
26
24
 
27
25
  def persist
28
- # Connections are not available from the runtime object, so
29
- # we rely on Schema::Tracer to save it for us
30
- value = resolved_value || resolve_from_runtime
26
+ value = final_value.dig(*path)
31
27
  FragmentCache.cache_store.write(cache_key, value, **options)
32
28
  end
33
29
 
@@ -41,10 +37,6 @@ module GraphQL
41
37
  context.namespace(:interpreter)
42
38
  end
43
39
 
44
- def resolve_from_runtime
45
- final_value.dig(*path)
46
- end
47
-
48
40
  def final_value
49
41
  @final_value ||= interpreter_context[:runtime].final_value
50
42
  end
@@ -22,8 +22,7 @@ module GraphQL
22
22
  fragment = Fragment.new(context, options)
23
23
 
24
24
  if (cached = fragment.read)
25
- return nil if cached == Fragment::NIL_IN_CACHE
26
- return restore_cached_value(cached)
25
+ return cached == Fragment::NIL_IN_CACHE ? nil : raw_value(cached)
27
26
  end
28
27
 
29
28
  (block_given? ? block.call : object_to_cache).tap do |resolved_value|
@@ -33,11 +32,6 @@ module GraphQL
33
32
 
34
33
  private
35
34
 
36
- def restore_cached_value(cached)
37
- # If we return connection object from resolver, Interpreter stops processing it
38
- connection? ? cached : raw_value(cached)
39
- end
40
-
41
35
  def field
42
36
  interpreter_context[:current_field]
43
37
  end
@@ -10,18 +10,15 @@ module GraphQL
10
10
  class << self
11
11
  def trace(key, data)
12
12
  yield.tap do |resolved_value|
13
- next unless connection_to_cache?(key, data)
13
+ next unless connection_field?(key, data)
14
14
 
15
- # We need to attach connection object to fragment and save it later
16
- context = data[:query].context
17
- verify_connections!(context)
18
- cache_connection(resolved_value, context)
15
+ verify_connections!(data[:query].context)
19
16
  end
20
17
  end
21
18
 
22
19
  private
23
20
 
24
- def connection_to_cache?(key, data)
21
+ def connection_field?(key, data)
25
22
  key == "execute_field" && data[:field].connection?
26
23
  end
27
24
 
@@ -31,12 +28,6 @@ module GraphQL
31
28
  raise StandardError,
32
29
  "GraphQL::Pagination::Connections should be enabled for connection caching"
33
30
  end
34
-
35
- def cache_connection(resolved_value, context)
36
- current_path = context.namespace(:interpreter)[:current_path]
37
- fragment = context.fragments.find { |fragment| fragment.path == current_path }
38
- fragment.resolved_value = resolved_value if fragment
39
- end
40
31
  end
41
32
  end
42
33
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module FragmentCache
5
- VERSION = "1.0.2"
5
+ VERSION = "1.0.3"
6
6
  end
7
7
  end
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.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-19 00:00:00.000000000 Z
11
+ date: 2020-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -168,6 +168,7 @@ files:
168
168
  - lib/graphql/fragment_cache.rb
169
169
  - lib/graphql/fragment_cache/cache_key_builder.rb
170
170
  - lib/graphql/fragment_cache/cacher.rb
171
+ - lib/graphql/fragment_cache/connections/patch.rb
171
172
  - lib/graphql/fragment_cache/ext/context_fragments.rb
172
173
  - lib/graphql/fragment_cache/ext/graphql_cache_key.rb
173
174
  - lib/graphql/fragment_cache/field_extension.rb