-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fusion] Correctly handle null items in ResolveByKey (#7217)
- Loading branch information
1 parent
3ce8a28
commit 27bcec2
Showing
5 changed files
with
270 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
.../__snapshots__/DemoIntegrationTests.ResolveByKey_Handles_Null_Item_Correctly.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# ResolveByKey_Handles_Null_Item_Correctly | ||
|
||
## Result | ||
|
||
```json | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Cannot return null for non-nullable field.", | ||
"locations": [ | ||
{ | ||
"line": 9, | ||
"column": 13 | ||
} | ||
], | ||
"path": [ | ||
"viewer", | ||
"recommendedResalableProducts", | ||
"edges", | ||
1, | ||
"node", | ||
"product", | ||
"name" | ||
], | ||
"extensions": { | ||
"code": "HC0018" | ||
} | ||
} | ||
], | ||
"data": { | ||
"viewer": { | ||
"recommendedResalableProducts": { | ||
"edges": [ | ||
{ | ||
"node": { | ||
"product": { | ||
"id": "UHJvZHVjdDox", | ||
"name": "Table" | ||
} | ||
} | ||
}, | ||
{ | ||
"node": { | ||
"product": null | ||
} | ||
}, | ||
{ | ||
"node": { | ||
"product": { | ||
"id": "UHJvZHVjdDoz", | ||
"name": "Chair" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Request | ||
|
||
```graphql | ||
{ | ||
viewer { | ||
recommendedResalableProducts { | ||
edges { | ||
node { | ||
product? { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## QueryPlan Hash | ||
|
||
```text | ||
143888B7D930092D26863B1CCBEFA6A7A06739E8 | ||
``` | ||
|
||
## QueryPlan | ||
|
||
```json | ||
{ | ||
"document": "{ viewer { recommendedResalableProducts { edges { node { product? { id name } } } } } }", | ||
"rootNode": { | ||
"type": "Sequence", | ||
"nodes": [ | ||
{ | ||
"type": "Resolve", | ||
"subgraph": "Resale", | ||
"document": "query fetch_viewer_1 { viewer { recommendedResalableProducts { edges { node { product? { id __fusion_exports__1: id } } } } } }", | ||
"selectionSetId": 0, | ||
"provides": [ | ||
{ | ||
"variable": "__fusion_exports__1" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "Compose", | ||
"selectionSetIds": [ | ||
0 | ||
] | ||
}, | ||
{ | ||
"type": "ResolveByKeyBatch", | ||
"subgraph": "Products", | ||
"document": "query fetch_viewer_2($__fusion_exports__1: [ID!]!) { nodes(ids: $__fusion_exports__1) { ... on Product { name __fusion_exports__1: id } } }", | ||
"selectionSetId": 5, | ||
"path": [ | ||
"nodes" | ||
], | ||
"requires": [ | ||
{ | ||
"variable": "__fusion_exports__1" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "Compose", | ||
"selectionSetIds": [ | ||
5 | ||
] | ||
} | ||
] | ||
}, | ||
"state": { | ||
"__fusion_exports__1": "Product_id" | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Relay; | ||
|
||
namespace HotChocolate.Fusion.Shared.Resale; | ||
|
||
[GraphQLName("Query")] | ||
public class ResaleQuery | ||
{ | ||
public Viewer GetViewer() => new(); | ||
|
||
[NodeResolver] | ||
public Product? GetProductById([ID] int id) => new(id); | ||
} | ||
|
||
public class Viewer | ||
{ | ||
[UsePaging] | ||
public List<RecommendedResalableProduct> GetRecommendedResalableProducts() | ||
{ | ||
return new() | ||
{ | ||
new RecommendedResalableProduct(new Product(1)), | ||
// This product doesn't exist on the products subgraph | ||
new RecommendedResalableProduct(new Product(5)), | ||
new RecommendedResalableProduct(new Product(3)) | ||
}; | ||
} | ||
} | ||
|
||
public record RecommendedResalableProduct(Product Product); | ||
|
||
public record Product([property: ID] int Id); |