GraphQL Hot Chocolate 12中countEarnings参数错误排查求助
问题修复说明
1. GraphQL查询参数大小写不匹配
错误提示的核心原因是参数名大小写不一致:
- 后端
countEarnings方法的参数名为PriceBay(首字母大写) - 你的GraphQL查询里写的是
priceBay(首字母小写)
GraphQL参数名区分大小写,修正后的查询如下:
query{ countEarnings(PriceBay: 3540, PriceSell: 5050, taxValue: 23) }
2. C#代码变量拼写错误
你的CountEarnings方法存在变量名拼写错误:参数定义的是PriceBay,但方法体内误用了未定义的PriceBuy,这会导致编译失败。修正后的C#代码:
public double RemoveTaxVat(double price, double taxVat) { taxVat = taxVat / 100; taxVat = taxVat + 1; price = price / taxVat; return price; } public double CountEarnings(double PriceBay, double PriceSell, double taxValue) { double earnings = RemoveTaxVat(PriceSell, taxValue) - PriceBay; return earnings; }
内容的提问来源于stack exchange,提问作者xoreee
相关产品推荐
相关产品推荐

