@@ -147,7 +147,7 @@ export class ApiClient {
147
147
query . cache = await this . request ( query . url , { headers } )
148
148
query . timestamp = new Date ( ) . getTime ( )
149
149
query . promise = null
150
-
150
+
151
151
const result = this . normalize ( query . cache )
152
152
153
153
this . dispatch ( {
@@ -199,33 +199,31 @@ export class ApiClient {
199
199
} )
200
200
201
201
if ( ! schema . error && ! schema . errors ) {
202
- let related = invalidate
202
+ let invalid
203
203
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 ]
208
208
}
209
209
210
210
this . cache . forEach ( q => {
211
211
if ( q . id && q . url === query . url && schema . data ) {
212
212
q . cache = schema
213
- return query . dispatch ( { result } )
213
+ return q . dispatch ( { result } )
214
214
}
215
215
216
- if ( ! related ) {
216
+ if ( ! invalid ) {
217
217
return
218
218
}
219
219
220
220
if ( ! q . type ) {
221
221
Object . assign ( q , getTypeMap ( q , this . schema ) )
222
222
}
223
223
224
- const invalid =
225
- q . type === type ||
226
- related . find ( r => query . relationships . indexOf ( r ) >= 0 )
224
+ const types = [ q . type , ...q . relationships ]
227
225
228
- if ( invalid ) {
226
+ if ( types . find ( t => invalid . indexOf ( t ) >= 0 ) ) {
229
227
q . cache = null
230
228
231
229
if ( q . subscribers . length ) {
0 commit comments