I'm trying to change the example of SchemStitching on GitHub to use it from a products service instead of a gateway service.
The idea is to extend schema of the product and include information from inventory & reviews.
The changes I make in the products service:
add stitiching.graphql
file with product type extension
extend type Product {
inStock: Boolean
@delegate(
schema: "inventory",
path: "inventoryInfo(upc: $fields:upc).isInStock")
shippingEstimate: Int
@delegate(
schema: "inventory"
path: "shippingEstimate(weight: $fields:weight price: $fields:price)")
reviews: [Review] @delegate(schema: "reviews" path:"reviewsByProduct(upc: $fields:upc)")
}
Change Startup.cs
to register remote schemas for inventory & reviews.
const string Inventory = "inventory";
const string Reviews = "reviews";
builder.Services.AddHttpClient(Inventory,
c => c.BaseAddress = new Uri("http://localhost:64309/graphql"));
builder.Services.AddHttpClient(Reviews,
c => c.BaseAddress = new Uri("http://localhost:64317/graphql"));
builder.Services
.AddSingleton<ProductRepository>()
.AddGraphQLServer()
.AddQueryType<Query>()
.AddRemoteSchema(Inventory, ignoreRootTypes: true)
.AddRemoteSchema(Reviews, ignoreRootTypes: true)
.AddTypeExtensionsFromFile("./Stitching.graphql");
When I run the application (running products, inventory, reviews services) in the hotchocolate playground running the following query
query {
product(upc: 3) {
name
inStock
}
}
I get back error for inStock
{
"errors": [
{
"message": "Variable `__fields_upc` is required.",
"extensions": {
"code": "HC0018",
"variable": "__fields_upc",
"remote": {
"message": "Variable `__fields_upc` is required.",
"extensions": {
"code": "HC0018",
"variable": "__fields_upc"
}
},
"schemaName": "inventory"
}
}
],
"data": {
"product": {
"name": "Chair",
"inStock": null
}
}
}
I can't figure out why upc field is not passed. It seems that validation fails on product service as I don't see any calls going out to inventory service.
Any clue what the issue is ?
I'm using ASP.NET 6 with
<PackageReference Include="HotChocolate.AspNetCore" Version="12.9.0" />
<PackageReference Include="HotChocolate.Stitching" Version="12.9.0" />
EDIT
It seems that $fields:upc
is not getting resolved for inventory schema, because if I update the stitching schema with hard coded upc of 3
extend type Product {
inStock: Boolean
@delegate(
schema: "inventory",
path: "inventoryInfo(upc: 3).isInStock")
}
And query the data
query {
product(upc: 3) {
upc
name
inStock
}
}
I get back results as expected
{
"data": {
"product": {
"upc": 3,
"name": "Chair",
"inStock": true
}
}
}