Skip to content

Commit

Permalink
Showcase issue without unions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Nov 17, 2024
1 parent 09bc10d commit ba91007
Show file tree
Hide file tree
Showing 2 changed files with 264 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/HotChocolate/Fusion/test/Core.Tests/DemoIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,79 @@ public class DemoIntegrationTests(ITestOutputHelper output)
{
private readonly Func<ICompositionLog> _logFactory = () => new TestCompositionLog(output);

[Fact]
public async Task Test()
{
// arrange
var subgraphA = await TestSubgraph.CreateAsync(
"""
interface Node {
id: ID!
}
type Query {
productsA: [Product]
productsB: [Product]
node(id: ID!): Node
nodes(ids: [ID!]!): [Node]!
}
type Product implements Node {
id: ID!
name: String!
}
""");

var subgraphB = await TestSubgraph.CreateAsync(
"""
interface Node {
id: ID!
}
type Query {
node(id: ID!): Node
nodes(ids: [ID!]!): [Node]!
}
type Product implements Node {
id: ID!
price: Float!
reviewCount: Int!
}
""");

using var subgraphs = new TestSubgraphCollection(output, [subgraphA, subgraphB]);
var executor = await subgraphs.GetExecutorAsync();
var request = Parse("""
query {
productsA {
id
name
price
reviewCount
}
productsB {
id
name
price
reviewCount
}
}
""");

// act
var result = await executor.ExecuteAsync(
OperationRequestBuilder
.New()
.SetDocument(request)
.Build());

// assert
var snapshot = new Snapshot();
CollectSnapshotData(snapshot, request, result);
await snapshot.MatchMarkdownAsync();
}

[Fact]
public async Task Authors_And_Reviews_AutoCompose()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Test

## Result

```json
{
"errors": [
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 11,
"column": 5
}
],
"path": [
"productsB",
2,
"price"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 11,
"column": 5
}
],
"path": [
"productsB",
1,
"price"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 11,
"column": 5
}
],
"path": [
"productsB",
0,
"price"
],
"extensions": {
"code": "HC0018"
}
}
],
"data": {
"productsA": [
{
"id": "1",
"name": "string",
"price": 123.456,
"reviewCount": 123
},
{
"id": "2",
"name": "string",
"price": 123.456,
"reviewCount": 123
},
{
"id": "3",
"name": "string",
"price": 123.456,
"reviewCount": 123
}
],
"productsB": [
null,
null,
null
]
}
}
```

## Request

```graphql
{
productsA {
id
name
price
reviewCount
}
productsB {
id
name
price
reviewCount
}
}
```

## QueryPlan Hash

```text
57DE21D1B552226339A985FBFA65E0DA2E33703C
```

## QueryPlan

```json
{
"document": "{ productsA { id name price reviewCount } productsB { id name price reviewCount } }",
"rootNode": {
"type": "Sequence",
"nodes": [
{
"type": "Resolve",
"subgraph": "Subgraph_1",
"document": "query fetch_productsA_productsB_1 { productsA { id name __fusion_exports__1: id } productsB { id name __fusion_exports__2: id } }",
"selectionSetId": 0,
"provides": [
{
"variable": "__fusion_exports__1"
},
{
"variable": "__fusion_exports__2"
}
]
},
{
"type": "Compose",
"selectionSetIds": [
0
]
},
{
"type": "Parallel",
"nodes": [
{
"type": "ResolveByKeyBatch",
"subgraph": "Subgraph_2",
"document": "query fetch_productsA_productsB_2($__fusion_exports__1: [ID!]!) { nodes(ids: $__fusion_exports__1) { ... on Product { price reviewCount __fusion_exports__1: id } } }",
"selectionSetId": 1,
"path": [
"nodes"
],
"requires": [
{
"variable": "__fusion_exports__1"
}
]
},
{
"type": "ResolveByKeyBatch",
"subgraph": "Subgraph_2",
"document": "query fetch_productsA_productsB_3($__fusion_exports__2: [ID!]!) { nodes(ids: $__fusion_exports__2) { ... on Product { price reviewCount __fusion_exports__2: id } } }",
"selectionSetId": 2,
"path": [
"nodes"
],
"requires": [
{
"variable": "__fusion_exports__2"
}
]
}
]
},
{
"type": "Compose",
"selectionSetIds": [
1,
2
]
}
]
},
"state": {
"__fusion_exports__1": "Product_id",
"__fusion_exports__2": "Product_id"
}
}
```

0 comments on commit ba91007

Please sign in to comment.