44namespace HotChocolate . Fusion ;
55
66// TODO:
7- // - Conditional selections (on, on top of and below node field, also with conditional fragment)
87// - Selections on interface, all types of interfaces are on same subgraph and there's only node lookup
98public class GlobalObjectIdentificationTests : FusionTestBase
109{
@@ -389,7 +388,7 @@ interface Node {
389388 id: ID!
390389 }
391390
392- type Discussion implements Node @key(fields: "id") {
391+ type Discussion implements Node {
393392 id: ID!
394393 title: String!
395394 }
@@ -407,7 +406,7 @@ interface Node {
407406 id: ID!
408407 }
409408
410- type Author implements Node @key(fields: "id") {
409+ type Author implements Node {
411410 id: ID!
412411 username: String!
413412 }
@@ -455,7 +454,7 @@ interface Node {
455454 id: ID!
456455 }
457456
458- type Discussion implements Node @key(fields: "id") {
457+ type Discussion implements Node {
459458 id: ID!
460459 title: String!
461460 }
@@ -556,7 +555,7 @@ ... on Discussion {
556555 await MatchSnapshotAsync ( gateway , request , result ) ;
557556 }
558557
559- [ Fact ]
558+ [ Fact ( Skip = "This behavior is incorrect" ) ]
560559 public async Task No_By_Id_Lookup_On_Best_Matching_Source_Schema ( )
561560 {
562561 // arrange
@@ -715,7 +714,7 @@ interface Node {
715714 id: ID!
716715 }
717716
718- type Discussion implements Node @key(fields: "id") {
717+ type Discussion implements Node {
719718 id: ID!
720719 title: String!
721720 }
@@ -768,7 +767,7 @@ interface Node {
768767 id: ID!
769768 }
770769
771- type Discussion implements Node @key(fields: "id") {
770+ type Discussion implements Node {
772771 id: ID!
773772 name: String
774773 }
@@ -785,7 +784,7 @@ interface Node {
785784 id: ID!
786785 }
787786
788- type Discussion implements Node @key(fields: "id") {
787+ type Discussion implements Node {
789788 id: ID!
790789 commentCount: Int
791790 }
@@ -837,13 +836,13 @@ interface Node {
837836 id: ID!
838837 }
839838
840- type Discussion implements Node @key(fields: "id") {
839+ type Discussion implements Node {
841840 id: ID!
842841 viewerRating: Float!
843842 product: Product
844843 }
845844
846- type Product @key(fields: "id") {
845+ type Product {
847846 id: ID!
848847 }
849848 """ ) ;
@@ -859,7 +858,7 @@ interface Node {
859858 id: ID!
860859 }
861860
862- type Product implements Node @key(fields: "id") {
861+ type Product implements Node {
863862 id: ID!
864863 name: String
865864 }
@@ -913,12 +912,12 @@ interface Node {
913912 id: ID!
914913 }
915914
916- type Discussion implements Node @key(fields: "id") {
915+ type Discussion implements Node {
917916 id: ID!
918917 product: Product
919918 }
920919
921- type Product @key(fields: "id") {
920+ type Product {
922921 id: ID!
923922 }
924923 """ ) ;
@@ -934,12 +933,12 @@ interface Node {
934933 id: ID!
935934 }
936935
937- type Review implements Node @key(fields: "id") {
936+ type Review implements Node {
938937 id: ID!
939938 product: Product
940939 }
941940
942- type Product @key(fields: "id") {
941+ type Product {
943942 id: ID!
944943 }
945944 """ ) ;
@@ -955,7 +954,7 @@ interface Node {
955954 id: ID!
956955 }
957956
958- type Product implements Node @key(fields: "id") {
957+ type Product implements Node {
959958 id: ID!
960959 name: String
961960 }
@@ -1013,12 +1012,12 @@ interface Node {
10131012 id: ID!
10141013 }
10151014
1016- type Discussion implements Node @key(fields: "id") {
1015+ type Discussion implements Node {
10171016 id: ID!
10181017 product: Product
10191018 }
10201019
1021- type Product @key(fields: "id") {
1020+ type Product {
10221021 id: ID!
10231022 }
10241023 """ ) ;
@@ -1034,12 +1033,12 @@ interface Node {
10341033 id: ID!
10351034 }
10361035
1037- type Review implements Node @key(fields: "id") {
1036+ type Review implements Node {
10381037 id: ID!
10391038 product: Product
10401039 }
10411040
1042- type Product @key(fields: "id") {
1041+ type Product {
10431042 id: ID!
10441043 }
10451044 """ ) ;
@@ -1055,7 +1054,7 @@ interface Node {
10551054 id: ID!
10561055 }
10571056
1058- type Product implements Node @key(fields: "id") {
1057+ type Product implements Node {
10591058 id: ID!
10601059 name: String
10611060 }
@@ -1118,13 +1117,13 @@ interface Votable {
11181117 viewerCanVote: Boolean!
11191118 }
11201119
1121- type Discussion implements Node & Votable @key(fields: "id") {
1120+ type Discussion implements Node & Votable {
11221121 id: ID!
11231122 viewerCanVote: Boolean!
11241123 viewerRating: Float!
11251124 }
11261125
1127- type Comment implements Node & Votable @key(fields: "id") {
1126+ type Comment implements Node & Votable {
11281127 id: ID!
11291128 viewerCanVote: Boolean!
11301129 }
@@ -1177,13 +1176,13 @@ interface Votable {
11771176 viewerCanVote: Boolean!
11781177 }
11791178
1180- type Discussion implements Node & Votable @key(fields: "id") {
1179+ type Discussion implements Node & Votable {
11811180 id: ID!
11821181 viewerCanVote: Boolean!
11831182 viewerRating: Float!
11841183 }
11851184
1186- type Comment implements Node & Votable @key(fields: "id") {
1185+ type Comment implements Node & Votable {
11871186 id: ID!
11881187 viewerCanVote: Boolean!
11891188 }
@@ -1239,18 +1238,18 @@ interface ProductList {
12391238 products: [Product]
12401239 }
12411240
1242- type Item1 implements Node & ProductList @key(fields: "id") {
1241+ type Item1 implements Node & ProductList {
12431242 id: ID!
12441243 products: [Product]
12451244 }
12461245
1247- type Item2 implements Node & ProductList @key(fields: "id") {
1246+ type Item2 implements Node & ProductList {
12481247 id: ID!
12491248 products: [Product]
12501249 singularProduct: Product
12511250 }
12521251
1253- type Product implements Node @key(fields: "id") {
1252+ type Product implements Node {
12541253 id: ID!
12551254 }
12561255 """ ) ;
@@ -1266,7 +1265,7 @@ interface Node {
12661265 id: ID!
12671266 }
12681267
1269- type Product implements Node @key(fields: "id") {
1268+ type Product implements Node {
12701269 id: ID!
12711270 name: String
12721271 }
@@ -1301,7 +1300,7 @@ ... on Item2 {
13011300 }
13021301 }
13031302 """ ,
1304- variables : new Dictionary < string , object ? > { [ "id" ] = /* Item1 :1 */ "SXRlbTE6MQ ==" } ) ;
1303+ variables : new Dictionary < string , object ? > { [ "id" ] = /* Item2 :1 */ "SXRlbTI6MQ ==" } ) ;
13051304
13061305 using var result = await client . PostAsync (
13071306 request ,
@@ -1330,17 +1329,17 @@ interface ProductList {
13301329 products: [Product]
13311330 }
13321331
1333- type Item1 implements Node & ProductList @key(fields: "id") {
1332+ type Item1 implements Node & ProductList {
13341333 id: ID!
13351334 products: [Product]
13361335 }
13371336
1338- type Item2 implements Node & ProductList @key(fields: "id") {
1337+ type Item2 implements Node & ProductList {
13391338 id: ID!
13401339 products: [Product]
13411340 }
13421341
1343- type Product implements Node @key(fields: "id") {
1342+ type Product implements Node {
13441343 id: ID!
13451344 }
13461345 """ ) ;
@@ -1356,7 +1355,7 @@ interface Node {
13561355 id: ID!
13571356 }
13581357
1359- type Product implements Node @key(fields: "id") {
1358+ type Product implements Node {
13601359 id: ID!
13611360 name: String
13621361 }
@@ -1394,4 +1393,86 @@ ... on ProductList {
13941393 // assert
13951394 await MatchSnapshotAsync ( gateway , request , result ) ;
13961395 }
1396+
1397+ [ Fact ]
1398+ public async Task Node_Field_Selections_On_Interface_And_Concrete_Type_Both_Have_Same_Dependency ( )
1399+ {
1400+ // arrange
1401+ using var server1 = CreateSourceSchema (
1402+ "A" ,
1403+ """
1404+ type Query {
1405+ node(id: ID!): Node @lookup
1406+ }
1407+
1408+ interface Node {
1409+ id: ID!
1410+ }
1411+
1412+ interface Authorable {
1413+ author: Author
1414+ }
1415+
1416+ type Discussion implements Node & Authorable {
1417+ id: ID!
1418+ author: Author
1419+ title: String
1420+ }
1421+
1422+ type Author implements Node {
1423+ id: ID!
1424+ }
1425+ """ ) ;
1426+
1427+ using var server2 = CreateSourceSchema (
1428+ "B" ,
1429+ """
1430+ type Query {
1431+ authorById(id: ID!): Author @lookup
1432+ }
1433+
1434+ type Author {
1435+ id: ID!
1436+ username: String
1437+ rating: Int
1438+ }
1439+ """ ) ;
1440+
1441+ using var gateway = await CreateCompositeSchemaAsync (
1442+ [
1443+ ( "A" , server1 ) ,
1444+ ( "B" , server2 )
1445+ ] ) ;
1446+
1447+ // act
1448+ using var client = GraphQLHttpClient . Create ( gateway . CreateClient ( ) ) ;
1449+
1450+ var request = new OperationRequest (
1451+ """
1452+ query testQuery($id: ID!) {
1453+ node(id: $id) {
1454+ __typename
1455+ id
1456+ ... on Authorable {
1457+ author {
1458+ username
1459+ }
1460+ }
1461+ ... on Discussion {
1462+ author {
1463+ rating
1464+ }
1465+ }
1466+ }
1467+ }
1468+ """ ,
1469+ variables : new Dictionary < string , object ? > { [ "id" ] = /* Discussion:1 */ "RGlzY3Vzc2lvbjox" } ) ;
1470+
1471+ using var result = await client . PostAsync (
1472+ request ,
1473+ new Uri ( "http://localhost:5000/graphql" ) ) ;
1474+
1475+ // assert
1476+ await MatchSnapshotAsync ( gateway , request , result ) ;
1477+ }
13971478}
0 commit comments