Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Oct 8, 2024
1 parent adcd989 commit 91d646d
Show file tree
Hide file tree
Showing 3 changed files with 329 additions and 0 deletions.
114 changes: 114 additions & 0 deletions src/HotChocolate/Fusion/test/Core.Tests/SubgraphErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
```

Original file line number Diff line number Diff line change
@@ -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"
}
}
```

0 comments on commit 91d646d

Please sign in to comment.