我已经实现了一个mutation
in C#
,我可以从中调用它,insomnia
但是使用我的类型查询相同的问题GraphQLHttpClient
被定义为
public class CheckOutType : ObjectGraphType
{
public CheckOutType(ICheckOutTypeService checkOutTypeService)
{
Field<NonNullGraphType<StringGraphType>>("EmailId");
Field<NonNullGraphType<StringGraphType>>("ClientCode");
}
}
public class CheckOutInputType : InputObjectGraphType
{
public CheckOutInputType(ICheckOutTypeService checkOutTypeService)
{
Field<NonNullGraphType<StringGraphType>>("EmailId");
Field<NonNullGraphType<StringGraphType>>("ClientCode");
}
}
突变定义为
public class CheckOutMutation : ObjectGraphType
{
public CheckOutMutation(ICheckOutTypeService checkOutTypeService)
{
Field<CheckOutType>(
"VRCheckOut",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<CheckOutInputType>> { Name = "CheckOutEntries" }
),
resolve: context =>
{
var checkOutData = context.GetArgument<CheckOut>("CheckOutEntries");
// some statement
return checkOutData;
});
}
}
这在失眠症中效果很好。参考是- 失眠有效的回应
但是,当我尝试在 C# 中调用相同的突变时,GraphQLHttpClient
它会返回一条错误消息,因为GraphQL.Validation.InvalidVariableError: Variable '$CheckOutInput' is invalid。没有为非空变量提供值。
下面是我用来调用突变的代码
string query = @"mutation CheckOutMutation($CheckOutInput:CheckOutInputType!)
{
checkOutMutation
{
vRCheckOut(checkOutEntries: $CheckOutInput)
{
emailId
clientCode
}
}
}";
GraphQLRequest queryObject = new GraphQLRequest()
{
Query = query,
Variables = new { emailId = "john@email.com",
clientCode = "ACC101" }
};
var client = new GraphQLHttpClient(ConfigSettings.BaseAPIUrl, new NewtonsoftJsonSerializer());
var response = client.SendMutationAsync<dynamic>(queryObject).Result;
您能否指导/提示,这其中缺少什么?