我试图写突变,但它给了我错误。
作为{"errors":[{"message":"Syntax Error: Expected $, found Name \"objects\"","locations":[{"line":2,"column":27}],"extensions":{"code":"GRAPHQL_PARSE_FAILED"}}]}
我写的代码是这样的。
[HttpGet("GraphDataCreate")]
public async Task<dynamic> ReturnGraphDataCreate()
{
using var graphQLClient = new GraphQLHttpClient("https://api.spacex.land/graphql/", new NewtonsoftJsonSerializer());
var trial = new GraphQLRequest
{
Query = @"
query insert_users(objects: { name: $name, rocket: $rocket }) {
returning {
id
name
rocket
timestamp
twitter
}
}",
OperationName = "insert_users",
Variables = new
{
name = "AdiAntNam",
rocket = "SPUTNIK5V"
}
};
var graphQLResponse = (object)(null);
try
{
graphQLResponse = await graphQLClient.SendQueryAsync<dynamic>(trial);
}
catch (Exception ex)
{
var err = ex;
string err1 = ex.Message;
string err2 = ex.InnerException.Message;
}
return Task.FromResult(graphQLResponse);
}
现在我在这部分缺少什么?我采取的参考是从这里。
https://github.com/graphql-dotnet/graphql-client