@@ -4,29 +4,25 @@ module GraphQL
4
4
module Cache
5
5
# Represents the caching resolver that wraps the existing resolver proc
6
6
class Resolver
7
- attr_accessor :type
8
-
9
- attr_accessor :field
10
-
11
- attr_accessor :orig_resolve_proc
7
+ attr_accessor :type , :field , :orig_resolve_proc
12
8
13
9
def initialize ( type , field )
14
10
@type = type
15
11
@field = field
16
12
end
17
13
18
14
def call ( obj , args , ctx )
19
- @orig_resolve_proc = field . resolve_proc
20
-
15
+ resolve_proc = proc { field . resolve_proc . call ( obj , args , ctx ) }
21
16
key = cache_key ( obj , args , ctx )
22
-
23
- value = Marshal [ key ] . read (
24
- field . metadata [ :cache ] , force : ctx [ :force_cache ]
25
- ) do
26
- @orig_resolve_proc . call ( obj , args , ctx )
17
+ metadata = field . metadata [ :cache ]
18
+
19
+ if field . connection?
20
+ Resolvers ::ConnectionResolver . new ( resolve_proc , key , metadata ) . call (
21
+ args : args , field : field , parent : obj , context : ctx , force_cache : ctx [ :force_cache ]
22
+ )
23
+ else
24
+ Resolvers ::ScalarResolver . new ( resolve_proc , key , metadata ) . call ( force_cache : ctx [ :force_cache ] )
27
25
end
28
-
29
- wrap_connections ( value , args , parent : obj , context : ctx )
30
26
end
31
27
32
28
protected
@@ -35,32 +31,6 @@ def call(obj, args, ctx)
35
31
def cache_key ( obj , args , ctx )
36
32
Key . new ( obj , args , type , field , ctx ) . to_s
37
33
end
38
-
39
- # @private
40
- def wrap_connections ( value , args , **kwargs )
41
- # return raw value if field isn't a connection (no need to wrap)
42
- return value unless field . connection?
43
-
44
- # return cached value if it is already a connection object
45
- # this occurs when the value is being resolved by GraphQL
46
- # and not being read from cache
47
- return value if value . class . ancestors . include? (
48
- GraphQL ::Relay ::BaseConnection
49
- )
50
-
51
- create_connection ( value , args , **kwargs )
52
- end
53
-
54
- # @private
55
- def create_connection ( value , args , **kwargs )
56
- GraphQL ::Relay ::BaseConnection . connection_for_nodes ( value ) . new (
57
- value ,
58
- args ,
59
- field : field ,
60
- parent : kwargs [ :parent ] ,
61
- context : kwargs [ :context ]
62
- )
63
- end
64
34
end
65
35
end
66
36
end
0 commit comments