@@ -32,50 +32,41 @@ def cached_resolve(type, field)
3232 lambda do |obj , args , ctx |
3333 key = cache_key ( obj , args , type , field )
3434
35- cached_value = Marshal [ key ] . read (
35+ value = Marshal [ key ] . read (
3636 field . metadata [ :cache ] , force : ctx [ :force_cache ]
3737 ) do
3838 old_resolve_proc . call ( obj , args , ctx )
3939 end
4040
41- wrap_connections ( cached_value , args , field , obj , ctx )
41+ wrap_connections ( value , args , field , obj , ctx )
4242 end
4343 end
4444
4545 # @private
46- def wrap_connections ( cached_value , args , field , obj , ctx )
47- # check for a connection implementation for this cached value
48- conn_class = cached_value . class . ancestors . find do |ancestor |
49- !connection_for ( ancestor . name ) . nil?
50- end
46+ def wrap_connections ( value , args , field , obj , ctx )
47+ # return raw value if field isn't a connection (no need to wrap)
48+ return value unless field . connection?
5149
52- if conn_class
53- create_connection ( conn_class , cached_value , args , field , obj , ctx )
54- else
55- # if we get here, this is not a connection
56- # value and should be returned as is
57- cached_value
58- end
59- end
50+ # return cached value if it is already a connection object
51+ # this occurs when the value is being resolved by GraphQL
52+ # and not being read from cache
53+ return value if value . class . ancestors . include? (
54+ GraphQL ::Relay ::BaseConnection
55+ )
6056
61- # @private
62- def connection_for ( name )
63- GraphQL ::Relay ::BaseConnection ::CONNECTION_IMPLEMENTATIONS [ name ]
57+ create_connection ( value , args , field , obj , ctx )
6458 end
6559
66- # rubocop:disable Metrics/ParameterLists
67-
6860 # @private
69- def create_connection ( conn_class , value , args , field , obj , ctx )
70- connection_for ( conn_class . name ) . new (
61+ def create_connection ( value , args , field , obj , ctx )
62+ GraphQL :: Relay :: BaseConnection . connection_for_nodes ( value ) . new (
7163 value ,
7264 args ,
7365 field : field ,
7466 parent : obj ,
7567 context : ctx
7668 )
7769 end
78- # rubocop:enable Metrics/ParameterLists
7970 end
8071 end
8172end
0 commit comments