@@ -16,6 +16,7 @@ import type {PayloadData, PayloadError} from '../network/RelayNetworkTypes';
16
16
import type {
17
17
NormalizationActorChange ,
18
18
NormalizationDefer ,
19
+ NormalizationInlineFragment ,
19
20
NormalizationLinkedField ,
20
21
NormalizationLiveResolverField ,
21
22
NormalizationModuleImport ,
@@ -243,34 +244,7 @@ class RelayResponseNormalizer {
243
244
break ;
244
245
}
245
246
case 'InlineFragment' : {
246
- const { abstractKey} = selection ;
247
- if ( abstractKey == null ) {
248
- const typeName = RelayModernRecord . getType ( record ) ;
249
- if ( typeName === selection . type ) {
250
- this . _traverseSelections ( selection , record , data ) ;
251
- }
252
- } else {
253
- // $FlowFixMe[method-unbinding] - data could be prototype less
254
- const implementsInterface = Object . prototype . hasOwnProperty . call (
255
- data ,
256
- abstractKey ,
257
- ) ;
258
- const typeName = RelayModernRecord . getType ( record ) ;
259
- const typeID = generateTypeID ( typeName ) ;
260
- let typeRecord = this . _recordSource . get ( typeID ) ;
261
- if ( typeRecord == null ) {
262
- typeRecord = RelayModernRecord . create ( typeID , TYPE_SCHEMA_TYPE ) ;
263
- this . _recordSource . set ( typeID , typeRecord ) ;
264
- }
265
- RelayModernRecord . setValue (
266
- typeRecord ,
267
- abstractKey ,
268
- implementsInterface ,
269
- ) ;
270
- if ( implementsInterface ) {
271
- this . _traverseSelections ( selection , record , data ) ;
272
- }
273
- }
247
+ this . _normalizeInlineFragment ( selection , record , data ) ;
274
248
break ;
275
249
}
276
250
case 'TypeDiscriminator' : {
@@ -358,13 +332,44 @@ class RelayResponseNormalizer {
358
332
}
359
333
}
360
334
335
+ _normalizeInlineFragment (
336
+ selection : NormalizationInlineFragment ,
337
+ record : Record ,
338
+ data : PayloadData ,
339
+ ) {
340
+ const { abstractKey} = selection ;
341
+ if ( abstractKey == null ) {
342
+ const typeName = RelayModernRecord . getType ( record ) ;
343
+ if ( typeName === selection . type ) {
344
+ this . _traverseSelections ( selection , record , data ) ;
345
+ }
346
+ } else {
347
+ // $FlowFixMe[method-unbinding] - data could be prototype less
348
+ const implementsInterface = Object . prototype . hasOwnProperty . call (
349
+ data ,
350
+ abstractKey ,
351
+ ) ;
352
+ const typeName = RelayModernRecord . getType ( record ) ;
353
+ const typeID = generateTypeID ( typeName ) ;
354
+ let typeRecord = this . _recordSource . get ( typeID ) ;
355
+ if ( typeRecord == null ) {
356
+ typeRecord = RelayModernRecord . create ( typeID , TYPE_SCHEMA_TYPE ) ;
357
+ this . _recordSource . set ( typeID , typeRecord ) ;
358
+ }
359
+ RelayModernRecord . setValue ( typeRecord , abstractKey , implementsInterface ) ;
360
+ if ( implementsInterface ) {
361
+ this . _traverseSelections ( selection , record , data ) ;
362
+ }
363
+ }
364
+ }
365
+
361
366
_normalizeResolver (
362
367
resolver : NormalizationResolverField | NormalizationLiveResolverField ,
363
368
record : Record ,
364
369
data : PayloadData ,
365
370
) {
366
371
if ( resolver . fragment != null ) {
367
- this . _traverseSelections ( resolver . fragment , record , data ) ;
372
+ this . _normalizeInlineFragment ( resolver . fragment , record , data ) ;
368
373
}
369
374
}
370
375
0 commit comments