如何使用GraphQL和从响应中接收数据.NET



我需要从响应字段(Banana Cake Pop(中获取文本,但不知道如何使用GraphQL nuget。我发现了类似的代码

var graphQLClient = new GraphQLHttpClient("url", new NewtonsoftJsonSerializer());
graphQLClient.HttpClient.DefaultRequestHeaders.Add("Authorization", "Bearer token");
graphQLClient.HttpClient.DefaultRequestHeaders.Add("Accept", "application/json");
var heroRequest = new GraphQLRequest
{
Query = @"
{query(
$propIdArray: [Uuid!], $objectIdArray: [Uuid!], $ts: String){
propertyViews(
propIdArray: $propIdArray, objectIdArray: $objectIdArray, ts: $ts
) {
id,
value,
valueTypeId
}
}}"
};
var graphQLResponse = await graphQLClient.SendQueryAsync<object>(heroRequest);

但它没有给我任何东西。香蕉蛋糕弹出页面的重新设置、变量和响应看起来像这个香蕉蛋糕弹出屏幕

解决方案非常简单。只需要在heroRequest中添加一个Variables属性。现在请求方法看起来像这个

var myRequest = new GraphQLRequest
{
Query = File.ReadAllText(path),
Variables = new
{
ts = string.Empty,
filterObject = new { parentId = $"{parentId}" },
sort = new { orders = new[] { new { direction = "ASC", property = "name" } } }
}
};
var graphQLResponse = _graphQLClient.SendQueryAsync<object>(myRequest);

最新更新