错误:找不到类型或名称空间“ GraphQLRequest”

时间:2019-06-26 12:43:11

标签: c# .net namespaces graphql using

当我编写以下代码时,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 }
};

1 个答案:

答案 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; }
}

更多信息的实现来源:https://github.com/JacekKosciesza/StarWars