@@ -16,6 +16,7 @@ import type {PayloadData, PayloadError} from '../network/RelayNetworkTypes';
1616import type {
1717 NormalizationActorChange ,
1818 NormalizationDefer ,
19+ NormalizationInlineFragment ,
1920 NormalizationLinkedField ,
2021 NormalizationLiveResolverField ,
2122 NormalizationModuleImport ,
@@ -243,34 +244,7 @@ class RelayResponseNormalizer {
243244 break ;
244245 }
245246 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 ) ;
274248 break ;
275249 }
276250 case 'TypeDiscriminator' : {
@@ -358,13 +332,44 @@ class RelayResponseNormalizer {
358332 }
359333 }
360334
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+
361366 _normalizeResolver (
362367 resolver : NormalizationResolverField | NormalizationLiveResolverField ,
363368 record : Record ,
364369 data : PayloadData ,
365370 ) {
366371 if ( resolver . fragment != null ) {
367- this . _traverseSelections ( resolver . fragment , record , data ) ;
372+ this . _normalizeInlineFragment ( resolver . fragment , record , data ) ;
368373 }
369374 }
370375
0 commit comments