@@ -791,6 +791,7 @@ class Merger {
791
791
private mergeObject ( sources : ( ObjectType | undefined ) [ ] , dest : ObjectType ) {
792
792
const isEntity = this . hintOnInconsistentEntity ( sources , dest ) ;
793
793
const isValueType = ! isEntity && ! dest . isRootType ( ) ;
794
+ const isSubscription = dest . isSubscriptionRootType ( ) ;
794
795
795
796
this . addFieldsShallow ( sources , dest ) ;
796
797
if ( ! dest . hasFields ( ) ) {
@@ -806,7 +807,15 @@ class Merger {
806
807
const subgraphFields = sources . map ( t => t ?. field ( destField . name ) ) ;
807
808
const mergeContext = this . validateOverride ( subgraphFields , destField ) ;
808
809
809
- this . mergeField ( subgraphFields , destField , mergeContext ) ;
810
+ if ( isSubscription ) {
811
+ this . validateSubscriptionField ( subgraphFields ) ;
812
+ }
813
+
814
+ this . mergeField ( {
815
+ sources : subgraphFields ,
816
+ dest : destField ,
817
+ mergeContext,
818
+ } ) ;
810
819
this . validateFieldSharing ( subgraphFields , destField , mergeContext ) ;
811
820
}
812
821
}
@@ -1085,7 +1094,7 @@ class Merger {
1085
1094
const { subgraphsWithOverride, subgraphMap } = sources . map ( ( source , idx ) => {
1086
1095
if ( ! source ) {
1087
1096
// While the subgraph may not have the field directly, it could have "stand-in" for that field
1088
- // through @interfaceObject , and it is those stand-ins that would be effectively overridden.
1097
+ // through @interfaceObject , and it is those stand-ins that would be effectively overridden.
1089
1098
const interfaceObjectAbstractingFields = this . fieldsInSourceIfAbstractedByInterfaceObject ( dest , idx ) ;
1090
1099
if ( interfaceObjectAbstractingFields . length > 0 ) {
1091
1100
return {
@@ -1251,7 +1260,15 @@ class Merger {
1251
1260
} ) . filter ( isDefined ) ;
1252
1261
}
1253
1262
1254
- private mergeField ( sources : FieldOrUndefinedArray , dest : FieldDefinition < any > , mergeContext : FieldMergeContext = new FieldMergeContext ( sources ) ) {
1263
+ private mergeField ( {
1264
+ sources,
1265
+ dest,
1266
+ mergeContext = new FieldMergeContext ( sources ) ,
1267
+ } : {
1268
+ sources : FieldOrUndefinedArray ,
1269
+ dest : FieldDefinition < any > ,
1270
+ mergeContext : FieldMergeContext ,
1271
+ } ) {
1255
1272
if ( sources . every ( ( s , i ) => s === undefined ? this . fieldsInSourceIfAbstractedByInterfaceObject ( dest , i ) . every ( ( f ) => this . isExternal ( i , f ) ) : this . isExternal ( i , s ) ) ) {
1256
1273
const definingSubgraphs = sources . map ( ( source , i ) => {
1257
1274
if ( source ) {
@@ -1790,7 +1807,11 @@ class Merger {
1790
1807
}
1791
1808
const subgraphFields = sources . map ( t => t ?. field ( destField . name ) ) ;
1792
1809
const mergeContext = this . validateOverride ( subgraphFields , destField ) ;
1793
- this . mergeField ( subgraphFields , destField , mergeContext ) ;
1810
+ this . mergeField ( {
1811
+ sources : subgraphFields ,
1812
+ dest : destField ,
1813
+ mergeContext,
1814
+ } ) ;
1794
1815
}
1795
1816
}
1796
1817
@@ -2805,4 +2826,16 @@ class Merger {
2805
2826
: err ;
2806
2827
} ) ;
2807
2828
}
2829
+
2830
+ private validateSubscriptionField ( sources : FieldOrUndefinedArray ) {
2831
+ // no subgraph marks field as @shareable
2832
+ const fieldsWithShareable = sources . filter ( ( src , idx ) => src && src . appliedDirectivesOf ( this . metadata ( idx ) . shareableDirective ( ) ) . length > 0 ) ;
2833
+ if ( fieldsWithShareable . length > 0 ) {
2834
+ const nodes = sourceASTs ( ...fieldsWithShareable ) ;
2835
+ this . errors . push ( ERRORS . INVALID_FIELD_SHARING . err (
2836
+ `Fields on root level subscription object cannot be marked as shareable` ,
2837
+ { nodes} ,
2838
+ ) ) ;
2839
+ }
2840
+ }
2808
2841
}
0 commit comments