From 91d646de8d47c47ea05de207203ecb413cd1d47e Mon Sep 17 00:00:00 2001 From: tobias-tengler <45513122+tobias-tengler@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:50:36 +0200 Subject: [PATCH] Add more tests --- .../test/Core.Tests/SubgraphErrorTests.cs | 114 +++++++++++++++++ ...d_Nullable_Both_Services_Error_SubField.md | 98 +++++++++++++++ ...d_Nullable_Both_Services_Error_SubField.md | 117 ++++++++++++++++++ 3 files changed, 329 insertions(+) create mode 100644 src/HotChocolate/Fusion/test/Core.Tests/__snapshots__/SubgraphErrorTests.Entity_Resolver_SubField_NonNull_EntryField_Nullable_Both_Services_Error_SubField.md create mode 100644 src/HotChocolate/Fusion/test/Core.Tests/__snapshots__/SubgraphErrorTests.Entity_Resolver_SubField_Nullable_EntryField_Nullable_Both_Services_Error_SubField.md diff --git a/src/HotChocolate/Fusion/test/Core.Tests/SubgraphErrorTests.cs b/src/HotChocolate/Fusion/test/Core.Tests/SubgraphErrorTests.cs index fbd994fe52a..ff87df1b671 100644 --- a/src/HotChocolate/Fusion/test/Core.Tests/SubgraphErrorTests.cs +++ b/src/HotChocolate/Fusion/test/Core.Tests/SubgraphErrorTests.cs @@ -2098,6 +2098,120 @@ interface Node { MatchMarkdownSnapshot(request, result); } + [Fact] + public async Task Entity_Resolver_SubField_NonNull_EntryField_Nullable_Both_Services_Error_SubField() + { + // arrange + var subgraphA = await TestSubgraph.CreateAsync( + """ + type Query { + productById(id: ID!): Product + } + + type Product implements Node { + id: ID! + name: String! + price: Float! @error + } + + interface Node { + id: ID! + } + """); + + var subgraphB = await TestSubgraph.CreateAsync( + """ + type Query { + productById(id: ID!): Product + } + + type Product implements Node { + id: ID! + score: Int! @error + } + + interface Node { + id: ID! + } + """); + + using var subgraphs = new TestSubgraphCollection(output, [subgraphA, subgraphB]); + var executor = await subgraphs.GetExecutorAsync(); + var request = """ + query { + productById(id: "1") { + id + name + price + score + } + } + """; + + // act + var result = await executor.ExecuteAsync(request); + + // assert + MatchMarkdownSnapshot(request, result); + } + + [Fact] + public async Task Entity_Resolver_SubField_Nullable_EntryField_Nullable_Both_Services_Error_SubField() + { + // arrange + var subgraphA = await TestSubgraph.CreateAsync( + """ + type Query { + productById(id: ID!): Product + } + + type Product implements Node { + id: ID! + name: String! + price: Float @error + } + + interface Node { + id: ID! + } + """); + + var subgraphB = await TestSubgraph.CreateAsync( + """ + type Query { + productById(id: ID!): Product + } + + type Product implements Node { + id: ID! + score: Int @error + } + + interface Node { + id: ID! + } + """); + + using var subgraphs = new TestSubgraphCollection(output, [subgraphA, subgraphB]); + var executor = await subgraphs.GetExecutorAsync(); + var request = """ + query { + productById(id: "1") { + id + name + price + score + } + } + """; + + // act + var result = await executor.ExecuteAsync(request); + + // assert + MatchMarkdownSnapshot(request, result); + } + #endregion #region Resolve Sequence diff --git a/src/HotChocolate/Fusion/test/Core.Tests/__snapshots__/SubgraphErrorTests.Entity_Resolver_SubField_NonNull_EntryField_Nullable_Both_Services_Error_SubField.md b/src/HotChocolate/Fusion/test/Core.Tests/__snapshots__/SubgraphErrorTests.Entity_Resolver_SubField_NonNull_EntryField_Nullable_Both_Services_Error_SubField.md new file mode 100644 index 00000000000..f32cf820454 --- /dev/null +++ b/src/HotChocolate/Fusion/test/Core.Tests/__snapshots__/SubgraphErrorTests.Entity_Resolver_SubField_NonNull_EntryField_Nullable_Both_Services_Error_SubField.md @@ -0,0 +1,98 @@ +# Entity_Resolver_SubField_NonNull_EntryField_Nullable_Both_Services_Error_SubField + +## Result + +```json +{ + "errors": [ + { + "message": "Unexpected Execution Error", + "locations": [ + { + "line": 2, + "column": 3 + } + ], + "path": [ + "productById" + ] + } + ], + "data": { + "productById": null + } +} +``` + +## Request + +```graphql +{ + productById(id: "1") { + id + name + price + score + } +} +``` + +## QueryPlan Hash + +```text +A5FE502D9F6F0548B898BC17A33BC0F2A2A13AE6 +``` + +## QueryPlan + +```json +{ + "document": "{ productById(id: \u00221\u0022) { id name price score } }", + "rootNode": { + "type": "Sequence", + "nodes": [ + { + "type": "Resolve", + "subgraph": "Subgraph_1", + "document": "query fetch_productById_1 { productById(id: \u00221\u0022) { id name price __fusion_exports__1: id } }", + "selectionSetId": 0, + "provides": [ + { + "variable": "__fusion_exports__1" + } + ] + }, + { + "type": "Compose", + "selectionSetIds": [ + 0 + ] + }, + { + "type": "Resolve", + "subgraph": "Subgraph_2", + "document": "query fetch_productById_2($__fusion_exports__1: ID!) { productById(id: $__fusion_exports__1) { score } }", + "selectionSetId": 1, + "path": [ + "productById" + ], + "requires": [ + { + "variable": "__fusion_exports__1" + } + ] + }, + { + "type": "Compose", + "selectionSetIds": [ + 1 + ] + } + ] + }, + "state": { + "__fusion_exports__1": "Product_id" + } +} +``` + diff --git a/src/HotChocolate/Fusion/test/Core.Tests/__snapshots__/SubgraphErrorTests.Entity_Resolver_SubField_Nullable_EntryField_Nullable_Both_Services_Error_SubField.md b/src/HotChocolate/Fusion/test/Core.Tests/__snapshots__/SubgraphErrorTests.Entity_Resolver_SubField_Nullable_EntryField_Nullable_Both_Services_Error_SubField.md new file mode 100644 index 00000000000..d9624056293 --- /dev/null +++ b/src/HotChocolate/Fusion/test/Core.Tests/__snapshots__/SubgraphErrorTests.Entity_Resolver_SubField_Nullable_EntryField_Nullable_Both_Services_Error_SubField.md @@ -0,0 +1,117 @@ +# Entity_Resolver_SubField_Nullable_EntryField_Nullable_Both_Services_Error_SubField + +## Result + +```json +{ + "errors": [ + { + "message": "Unexpected Execution Error", + "locations": [ + { + "line": 5, + "column": 5 + } + ], + "path": [ + "productById", + "price" + ] + }, + { + "message": "Unexpected Execution Error", + "locations": [ + { + "line": 6, + "column": 5 + } + ], + "path": [ + "productById", + "score" + ] + } + ], + "data": { + "productById": { + "id": "1", + "name": "string", + "price": null, + "score": null + } + } +} +``` + +## Request + +```graphql +{ + productById(id: "1") { + id + name + price + score + } +} +``` + +## QueryPlan Hash + +```text +A5FE502D9F6F0548B898BC17A33BC0F2A2A13AE6 +``` + +## QueryPlan + +```json +{ + "document": "{ productById(id: \u00221\u0022) { id name price score } }", + "rootNode": { + "type": "Sequence", + "nodes": [ + { + "type": "Resolve", + "subgraph": "Subgraph_1", + "document": "query fetch_productById_1 { productById(id: \u00221\u0022) { id name price __fusion_exports__1: id } }", + "selectionSetId": 0, + "provides": [ + { + "variable": "__fusion_exports__1" + } + ] + }, + { + "type": "Compose", + "selectionSetIds": [ + 0 + ] + }, + { + "type": "Resolve", + "subgraph": "Subgraph_2", + "document": "query fetch_productById_2($__fusion_exports__1: ID!) { productById(id: $__fusion_exports__1) { score } }", + "selectionSetId": 1, + "path": [ + "productById" + ], + "requires": [ + { + "variable": "__fusion_exports__1" + } + ] + }, + { + "type": "Compose", + "selectionSetIds": [ + 1 + ] + } + ] + }, + "state": { + "__fusion_exports__1": "Product_id" + } +} +``` +