Skip to content

Commit

Permalink
Isolate problem further
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Nov 10, 2024
1 parent ab1da37 commit 3e6743c
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 106 deletions.
91 changes: 85 additions & 6 deletions src/HotChocolate/Fusion/test/Core.Tests/UnionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,81 @@ ... on Item3 {
Assert.False(subgraphB.HasReceivedRequest);
}

[Fact]
public async Task Union_List_With_Differing_Union_Item_Dependencies_SameSelections()
{
// arrange
var subgraphA = await TestSubgraph.CreateAsync(
configure: builder =>
{
builder
.AddQueryType<SubgraphA_Query>()
.AddType<ISomeUnion>()
.AddType<SubgraphA_Item1>()
.AddType<SubgraphA_Item2>()
.AddType<SubgraphA_Item3>()
.AddType<SubgraphA_Product>()
.AddType<SubgraphA_Review>()
.ModifyOptions(o => o.EnsureAllNodesCanBeResolved = false)
.AddGlobalObjectIdentification();
});

var subgraphB = await TestSubgraph.CreateAsync(
configure: builder =>
{
builder
.AddQueryType()
.AddType<SubgraphB_Product>()
.AddType<SubgraphB_Review>()
.AddGlobalObjectIdentification();
});

using var subgraphs = new TestSubgraphCollection(output, [subgraphA, subgraphB]);
var executor = await subgraphs.GetExecutorAsync();
var request = Parse("""
query {
listOfUnion {
__typename
... on Item1 {
something
product {
id
name
}
}
... on Item2 {
other
product {
id
name
}
}
... on Item3 {
another
review {
id
score
}
}
}
}
""");

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

// assert
var snapshot = new Snapshot();
CollectSnapshotData(snapshot, request, result);
await snapshot.MatchMarkdownAsync();
// Ideally it would just be one request, but that's for another day...
Assert.Equal(3, subgraphB.NumberOfReceivedRequests);
}

[Fact]
public async Task Union_List_With_Differing_Union_Item_Dependencies()
{
Expand Down Expand Up @@ -453,7 +528,6 @@ ... on Item1 {
... on Item2 {
other
product {
id
name
}
}
Expand All @@ -479,6 +553,8 @@ ... on Item3 {
var snapshot = new Snapshot();
CollectSnapshotData(snapshot, request, result);
await snapshot.MatchMarkdownAsync();
// Ideally it would just be one request, but that's for another day...
Assert.Equal(3, subgraphB.NumberOfReceivedRequests);
}

[ObjectType("Query")]
Expand All @@ -488,18 +564,21 @@ public ISomeUnion GetUnion(int item)
{
return item switch
{
1 => new SubgraphA_Item1("Something", new SubgraphA_Product(2)),
_ => new SubgraphA_Item3(true, new SubgraphA_Review(1))
1 => new SubgraphA_Item1("Something", new SubgraphA_Product(1)),
_ => new SubgraphA_Item3(true, new SubgraphA_Review(2))
};
}

public List<ISomeUnion> GetListOfUnion()
{
return
[
new SubgraphA_Item1("Something", new SubgraphA_Product(2)),
new SubgraphA_Item2(123, new SubgraphA_Product(4)),
new SubgraphA_Item3(true, new SubgraphA_Review(1))
new SubgraphA_Item1("Something", new SubgraphA_Product(1)),
new SubgraphA_Item2(123, new SubgraphA_Product(2)),
new SubgraphA_Item3(true, new SubgraphA_Review(3)),
new SubgraphA_Item1("Something", new SubgraphA_Product(4)),
new SubgraphA_Item2(123, new SubgraphA_Product(5)),
new SubgraphA_Item3(true, new SubgraphA_Review(6))
];
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,56 @@

```json
{
"errors": [
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 15,
"column": 9
"data": {
"listOfUnion": [
{
"__typename": "Item1",
"something": "Something",
"product": {
"id": "UHJvZHVjdDox",
"name": "Product_1"
}
],
"path": [
"listOfUnion",
1,
"product",
"name"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 15,
"column": 9
},
{
"__typename": "Item2",
"other": 123,
"product": {
"name": "Product_2"
}
},
{
"__typename": "Item3",
"another": true,
"review": {
"id": "UmV2aWV3OjM=",
"score": 3
}
},
{
"__typename": "Item1",
"something": "Something",
"product": {
"id": "UHJvZHVjdDo0",
"name": "Product_4"
}
},
{
"__typename": "Item2",
"other": 123,
"product": {
"name": "Product_5"
}
},
{
"__typename": "Item3",
"another": true,
"review": {
"id": "UmV2aWV3OjY=",
"score": 1
}
],
"path": [
"listOfUnion",
0,
"product",
"name"
],
"extensions": {
"code": "HC0018"
}
}
],
"data": null
]
}
}
```

Expand All @@ -62,7 +73,6 @@
... on Item2 {
other
product {
id
name
}
}
Expand All @@ -80,28 +90,31 @@
## QueryPlan Hash

```text
51CA519135EDC9C49C71D22D7EF0562D417753EA
6F3D15770F165F5A7166C5598F4B1A7D6910A88D
```

## QueryPlan

```json
{
"document": "{ listOfUnion { __typename ... on Item1 { something product { id name } } ... on Item2 { other product { id name } } ... on Item3 { another review { id score } } } }",
"document": "{ listOfUnion { __typename ... on Item1 { something product { id name } } ... on Item2 { other product { name } } ... on Item3 { another review { id score } } } }",
"rootNode": {
"type": "Sequence",
"nodes": [
{
"type": "Resolve",
"subgraph": "Subgraph_1",
"document": "query fetch_listOfUnion_1 { listOfUnion { __typename ... on Item3 { __typename another review { id __fusion_exports__1: id } } ... on Item2 { __typename other product { id __fusion_exports__2: id } } ... on Item1 { __typename something product { id __fusion_exports__2: id } } } }",
"document": "query fetch_listOfUnion_1 { listOfUnion { __typename ... on Item3 { __typename another review { id __fusion_exports__1: id } } ... on Item2 { __typename other product { __fusion_exports__2: id } } ... on Item1 { __typename something product { id __fusion_exports__3: id } } } }",
"selectionSetId": 0,
"provides": [
{
"variable": "__fusion_exports__1"
},
{
"variable": "__fusion_exports__2"
},
{
"variable": "__fusion_exports__3"
}
]
},
Expand Down Expand Up @@ -145,14 +158,14 @@
{
"type": "ResolveByKeyBatch",
"subgraph": "Subgraph_2",
"document": "query fetch_listOfUnion_4($__fusion_exports__2: [ID!]!) { nodes(ids: $__fusion_exports__2) { ... on Product { name __fusion_exports__2: id } } }",
"selectionSetId": 5,
"document": "query fetch_listOfUnion_4($__fusion_exports__3: [ID!]!) { nodes(ids: $__fusion_exports__3) { ... on Product { name __fusion_exports__3: id } } }",
"selectionSetId": 6,
"path": [
"nodes"
],
"requires": [
{
"variable": "__fusion_exports__2"
"variable": "__fusion_exports__3"
}
]
}
Expand All @@ -162,14 +175,16 @@
"type": "Compose",
"selectionSetIds": [
4,
5
5,
6
]
}
]
},
"state": {
"__fusion_exports__1": "Review_id",
"__fusion_exports__2": "Product_id"
"__fusion_exports__2": "Product_id",
"__fusion_exports__3": "Product_id"
}
}
```
Expand Down
Loading

0 comments on commit 3e6743c

Please sign in to comment.