我在服务器端定义了一个查询
public TradeQuery(ITradeService tradeservice)
{
Name = nameof(TradeQuery);
Field<ListGraphType<TradeType>>("trades", resolve: r => { return tradeservice.GetTrades(); });
}
当我从 GraphiQL 客户端调用时,我得到了正确的响应。来自 GraphiQL 的请求是
{
tradeQuery {
trades {
id
price
quantity
}
}
}
并得到回应
{"data": {
"tradeQuery": {
"trades": [
{
"id": 3,
"price": 600,
"quantity": 600
},
{
"id": 4,
"price": 100,
"quantity": 100
}]}}}
但是当我尝试使用GraphQLHttpClient
它调用相同的查询时,它返回为 null 在下面的代码中,我在availableTrades
对象中得到了 null 值。
string apiEndpoint = "https://localhost:44342/graphql";
var graphQLClient = new GraphQLHttpClient(new GraphQLHttpClientOptions {
EndPoint = new Uri (apiEndpoint)
}, new NewtonsoftJsonSerializer());
var tradeQuery = @"{
tradeQuery{
trades {
id
price
quantity}}}";
GraphQLRequest graphQLRequest = new GraphQLRequest(tradeQuery);
var tradeQueryResponse = await graphQLClient.SendQueryAsync<TradeQuery>(graphQLRequest);
var availableTrades = tradeQueryResponse.Data.Trades;
响应类型TradeQuery
对象定义如下
public class TradeQuery
{
public List<Trade> Trades { get; set; }
}
你能指导一下可能出了什么问题吗?