@@ -147,7 +147,7 @@ export class ApiClient {
147147 query . cache = await this . request ( query . url , { headers } )
148148 query . timestamp = new Date ( ) . getTime ( )
149149 query . promise = null
150-
150+
151151 const result = this . normalize ( query . cache )
152152
153153 this . dispatch ( {
@@ -199,33 +199,31 @@ export class ApiClient {
199199 } )
200200
201201 if ( ! schema . error && ! schema . errors ) {
202- let related = invalidate
202+ let invalid
203203
204- if ( related === undefined ) {
205- related = relationships . length ? relationships : null
206- } else if ( related && ! Array . isArray ( related ) ) {
207- related = [ related ]
204+ if ( invalidate ) {
205+ invalid = Array . isArray ( invalidate ) ? invalidate : [ invalidate ]
206+ } else if ( invalidate !== false ) {
207+ invalid = [ type , ... relationships ]
208208 }
209209
210210 this . cache . forEach ( q => {
211211 if ( q . id && q . url === query . url && schema . data ) {
212212 q . cache = schema
213- return query . dispatch ( { result } )
213+ return q . dispatch ( { result } )
214214 }
215215
216- if ( ! related ) {
216+ if ( ! invalid ) {
217217 return
218218 }
219219
220220 if ( ! q . type ) {
221221 Object . assign ( q , getTypeMap ( q , this . schema ) )
222222 }
223223
224- const invalid =
225- q . type === type ||
226- related . find ( r => query . relationships . indexOf ( r ) >= 0 )
224+ const types = [ q . type , ...q . relationships ]
227225
228- if ( invalid ) {
226+ if ( types . find ( t => invalid . indexOf ( t ) >= 0 ) ) {
229227 q . cache = null
230228
231229 if ( q . subscribers . length ) {
0 commit comments