当我编写以下代码时,Visual Studio会显示一个错误,表明即使我在以下链接上从nuget安装了软件包,也找不到GraphQL:https://www.nuget.org/packages/GraphQL/,并使用GraphQL.Http; < / p>
var query = @"query($id: String) { device (id: $id) { displayName, id } }";
var request = new GraphQLRequest()
{
Query = query,
Variables = new { id = 123 }
};
答案 0 :(得分:0)
GraphQLRequest不是作为GraphQL软件包的一部分提供的类,它是您自己创建的类。
例如
select line,
datediff(hour, min(failure), max(failure)) / nullif(count(*) - 1, 0)
from test_failure f
group by line;
此类定义您要设置的“查询和变量”属性。然后,您将传递该对象进行查询。
API控制器中的代码如下所示:
public class GraphQLQuery
{
public string OperationName { get; set; }
public string NamedQuery { get; set; }
public string Query { get; set; }
public JObject Variables { get; set; }
}