@@ -118,7 +118,7 @@ public final class ApolloStore {
118118 }
119119 }
120120
121- func load< Query: GraphQLQuery > ( query: Query ) -> Promise < GraphQLResult < Query . Data > > {
121+ public func load< Query: GraphQLQuery > ( query: Query ) -> Promise < GraphQLResult < Query . Data > > {
122122 return withinReadTransaction { transaction in
123123 let mapper = GraphQLSelectionSetMapper < Query . Data > ( )
124124 let dependencyTracker = GraphQLDependencyTracker ( )
@@ -129,7 +129,7 @@ public final class ApolloStore {
129129 }
130130 }
131131
132- func load< Query: GraphQLQuery > ( query: Query , resultHandler: @escaping OperationResultHandler < Query > ) {
132+ public func load< Query: GraphQLQuery > ( query: Query , resultHandler: @escaping OperationResultHandler < Query > ) {
133133 load ( query: query) . andThen { result in
134134 resultHandler ( result, nil )
135135 } . catch { error in
@@ -143,17 +143,6 @@ public final class ApolloStore {
143143
144144 fileprivate lazy var loader : DataLoader < CacheKey , Record ? > = DataLoader ( self . cache. loadRecords)
145145
146- fileprivate func makeExecutor( ) -> GraphQLExecutor {
147- let executor = GraphQLExecutor { object, info in
148- let value = object [ info. cacheKeyForField]
149- return self . complete ( value: value)
150- }
151-
152- executor. dispatchDataLoads = self . loader. dispatch
153- executor. cacheKeyForObject = self . cacheKeyForObject
154- return executor
155- }
156-
157146 init ( cache: NormalizedCache , cacheKeyForObject: CacheKeyForObject ? ) {
158147 self . cache = cache
159148 self . cacheKeyForObject = cacheKeyForObject
@@ -187,7 +176,16 @@ public final class ApolloStore {
187176
188177 final func execute< Accumulator: GraphQLResultAccumulator > ( selections: [ GraphQLSelection ] , onObjectWithKey key: CacheKey , variables: GraphQLMap ? , accumulator: Accumulator ) throws -> Promise < Accumulator . FinalResult > {
189178 return loadObject ( forKey: key) . flatMap { object in
190- try self . makeExecutor ( ) . execute ( selections: selections, on: object, withKey: key, variables: variables, accumulator: accumulator)
179+ let executor = GraphQLExecutor { object, info in
180+ let value = object [ info. cacheKeyForField]
181+ return self . complete ( value: value)
182+ }
183+
184+
185+ executor. dispatchDataLoads = self . loader. dispatch
186+ executor. cacheKeyForObject = self . cacheKeyForObject
187+
188+ return try executor. execute ( selections: selections, on: object, withKey: key, variables: variables, accumulator: accumulator)
191189 }
192190 }
193191
@@ -206,8 +204,8 @@ public final class ApolloStore {
206204 fileprivate var updateChangedKeysFunc : DidChangeKeysFunc ?
207205
208206 init ( cache: NormalizedCache , cacheKeyForObject: CacheKeyForObject ? , updateChangedKeysFunc: @escaping DidChangeKeysFunc ) {
209- self . updateChangedKeysFunc = updateChangedKeysFunc
210- super. init ( cache: cache, cacheKeyForObject: cacheKeyForObject)
207+ self . updateChangedKeysFunc = updateChangedKeysFunc
208+ super. init ( cache: cache, cacheKeyForObject: cacheKeyForObject)
211209 }
212210
213211 public func update< Query: GraphQLQuery > ( query: Query , _ body: ( inout Query . Data ) throws -> Void ) throws {
@@ -232,12 +230,18 @@ public final class ApolloStore {
232230
233231 private func write( object: JSONObject , forSelections selections: [ GraphQLSelection ] , withKey key: CacheKey , variables: GraphQLMap ? ) throws {
234232 let normalizer = GraphQLResultNormalizer ( )
235- try self . makeExecutor ( ) . execute ( selections: selections, on: object, withKey: key, variables: variables, accumulator: normalizer)
233+ let executor = GraphQLExecutor { object, info in
234+ return . result( . success( object [ info. responseKeyForField] ) )
235+ }
236+
237+ executor. cacheKeyForObject = self . cacheKeyForObject
238+
239+ try executor. execute ( selections: selections, on: object, withKey: key, variables: variables, accumulator: normalizer)
236240 . flatMap {
237241 self . cache. merge ( records: $0)
238242 } . andThen { changedKeys in
239243 if let didChangeKeysFunc = self . updateChangedKeysFunc {
240- didChangeKeysFunc ( changedKeys, nil )
244+ didChangeKeysFunc ( changedKeys, nil )
241245 }
242246 } . wait ( )
243247 }
0 commit comments