@@ -3137,6 +3137,26 @@ export abstract class FragmentSelection extends AbstractSelection<FragmentElemen
3137
3137
abstract equals ( that : Selection ) : boolean ;
3138
3138
3139
3139
abstract contains ( that : Selection , options ?: { ignoreMissingTypename ?: boolean } ) : ContainsResult ;
3140
+
3141
+ normalize ( { parentType, recursive } : { parentType : CompositeType , recursive ? : boolean } ) : FragmentSelection | SelectionSet | undefined {
3142
+ const thisCondition = this . element . typeCondition ;
3143
+
3144
+ // This method assumes by contract that `parentType` runtimes intersects `this.parentType`'s, but `parentType`
3145
+ // runtimes may be a subset. So first check if the selection should not be discarded on that account (that
3146
+ // is, we should not keep the selection if its condition runtimes don't intersect at all with those of
3147
+ // `parentType` as that would ultimately make an invalid selection set).
3148
+ if ( thisCondition && parentType !== this . parentType ) {
3149
+ const conditionRuntimes = possibleRuntimeTypes ( thisCondition ) ;
3150
+ const typeRuntimes = possibleRuntimeTypes ( parentType ) ;
3151
+ if ( ! conditionRuntimes . some ( ( t ) => typeRuntimes . includes ( t ) ) ) {
3152
+ return undefined ;
3153
+ }
3154
+ }
3155
+
3156
+ return this . normalizeKnowingItIntersects ( { parentType, recursive } ) ;
3157
+ }
3158
+
3159
+ protected abstract normalizeKnowingItIntersects ( { parentType, recursive } : { parentType : CompositeType , recursive ? : boolean } ) : FragmentSelection | SelectionSet | undefined ;
3140
3160
}
3141
3161
3142
3162
class InlineFragmentSelection extends FragmentSelection {
@@ -3317,21 +3337,9 @@ class InlineFragmentSelection extends FragmentSelection {
3317
3337
: this . withUpdatedComponents ( newElement , newSelection ) ;
3318
3338
}
3319
3339
3320
- normalize ( { parentType, recursive } : { parentType : CompositeType , recursive ? : boolean } ) : FragmentSelection | SelectionSet | undefined {
3340
+ protected normalizeKnowingItIntersects ( { parentType, recursive } : { parentType : CompositeType , recursive ? : boolean } ) : FragmentSelection | SelectionSet | undefined {
3321
3341
const thisCondition = this . element . typeCondition ;
3322
3342
3323
- // This method assumes by contract that `parentType` runtimes intersects `this.parentType`'s, but `parentType`
3324
- // runtimes may be a subset. So first check if the selection should not be discarded on that account (that
3325
- // is, we should not keep the selection if its condition runtimes don't intersect at all with those of
3326
- // `parentType` as that would ultimately make an invalid selection set).
3327
- if ( thisCondition && parentType !== this . parentType ) {
3328
- const conditionRuntimes = possibleRuntimeTypes ( thisCondition ) ;
3329
- const typeRuntimes = possibleRuntimeTypes ( parentType ) ;
3330
- if ( ! conditionRuntimes . some ( ( t ) => typeRuntimes . includes ( t ) ) ) {
3331
- return undefined ;
3332
- }
3333
- }
3334
-
3335
3343
// We know the condition is "valid", but it may not be useful. That said, if the condition has directives,
3336
3344
// we preserve the fragment no matter what.
3337
3345
if ( this . element . appliedDirectives . length === 0 ) {
@@ -3472,7 +3480,7 @@ class FragmentSpreadSelection extends FragmentSelection {
3472
3480
assert ( false , `Unsupported` ) ;
3473
3481
}
3474
3482
3475
- normalize ( { parentType } : { parentType : CompositeType } ) : FragmentSelection {
3483
+ normalizeKnowingItIntersects ( { parentType } : { parentType : CompositeType } ) : FragmentSelection {
3476
3484
// We must update the spread parent type if necessary since we're not going deeper,
3477
3485
// or we'll be fundamentally losing context.
3478
3486
assert ( parentType . schema ( ) === this . parentType . schema ( ) , 'Should not try to normalize using a type from another schema' ) ;
0 commit comments