File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -4901,6 +4901,7 @@ pub(crate) fn normalize_operation(
4901
4901
schema,
4902
4902
NormalizeSelectionOption :: NormalizeRecursively ,
4903
4903
) ?;
4904
+ remove_introspection ( & mut normalized_selection_set) ;
4904
4905
normalized_selection_set. optimize_sibling_typenames ( interface_types_with_interface_objects) ?;
4905
4906
4906
4907
let normalized_operation = Operation {
@@ -4915,6 +4916,21 @@ pub(crate) fn normalize_operation(
4915
4916
Ok ( normalized_operation)
4916
4917
}
4917
4918
4919
+ // PORT_NOTE: This is a port of `withoutIntrospection` from JS version.
4920
+ fn remove_introspection ( selection_set : & mut SelectionSet ) {
4921
+ // Note that, because we only apply this to the top-level selections, we skip all
4922
+ // introspection, including __typename. In general, we don't want to ignore __typename during
4923
+ // query plans, but at top-level, we can let the router execution deal with it rather than
4924
+ // querying some service for that.
4925
+
4926
+ Arc :: make_mut ( & mut selection_set. selections ) . retain ( |_, selection| {
4927
+ !matches ! ( selection,
4928
+ Selection :: Field ( field_selection) if
4929
+ field_selection. field. field_position. is_introspection_typename_field( )
4930
+ )
4931
+ } ) ;
4932
+ }
4933
+
4918
4934
fn runtime_types_intersect (
4919
4935
type1 : & CompositeTypeDefinitionPosition ,
4920
4936
type2 : & CompositeTypeDefinitionPosition ,
Original file line number Diff line number Diff line change @@ -1313,4 +1313,51 @@ type User
1313
1313
}
1314
1314
"### ) ;
1315
1315
}
1316
+
1317
+ #[ test]
1318
+ fn drop_operation_root_level_typename ( ) {
1319
+ let subgraph1 = Subgraph :: parse_and_expand (
1320
+ "Subgraph1" ,
1321
+ "https://Subgraph1" ,
1322
+ r#"
1323
+ type Query {
1324
+ t: T
1325
+ }
1326
+
1327
+ type T @key(fields: "id") {
1328
+ id: ID!
1329
+ x: Int
1330
+ }
1331
+ "# ,
1332
+ )
1333
+ . unwrap ( ) ;
1334
+ let subgraphs = vec ! [ & subgraph1] ;
1335
+ let supergraph = Supergraph :: compose ( subgraphs) . unwrap ( ) ;
1336
+ let planner = QueryPlanner :: new ( & supergraph, Default :: default ( ) ) . unwrap ( ) ;
1337
+ let document = ExecutableDocument :: parse_and_validate (
1338
+ planner. api_schema ( ) . schema ( ) ,
1339
+ r#"
1340
+ query {
1341
+ __typename
1342
+ t {
1343
+ x
1344
+ }
1345
+ }
1346
+ "# ,
1347
+ "operation.graphql" ,
1348
+ )
1349
+ . unwrap ( ) ;
1350
+ let plan = planner. build_query_plan ( & document, None ) . unwrap ( ) ;
1351
+ insta:: assert_snapshot!( plan, @r###"
1352
+ QueryPlan {
1353
+ Fetch(service: "Subgraph1") {
1354
+ {
1355
+ t {
1356
+ x
1357
+ }
1358
+ }
1359
+ },
1360
+ }
1361
+ "### ) ;
1362
+ }
1316
1363
}
You can’t perform that action at this time.
0 commit comments