如何返回成功执行的响应?结果对象已填充,但在尝试解析 result.Data 时出现递归错误。
> Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'parent' with type
> 'GraphQL.Execution.ObjectExecutionNode'. Path
> 'subFields[0].items[0].subFields[0]'.
> at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter
> writer, Object value, JsonProperty property, JsonContract contract,
> JsonContainerContract containerContract, JsonProperty
> containerProperty)
我尝试了多个步骤,不确定我错过了什么?似乎这很简单。
public async Task<IActionResult> Post([FromBody] GraphQLQuery query)
{
//var inputs = query.Variables.ToInputs();
//Inputs inputs = new Inputs(null);
var result = await new DocumentExecuter().ExecuteAsync(_ =>
{
_.Schema = _weatherSchema;
_.Query = query.Query;
_.OperationName = query.OperationName;
//_.Inputs = inputs;
});
var opt = new JsonSerializerOptions()
{
WriteIndented = true,
MaxDepth = 4,
PropertyNameCaseInsensitive = true
};
//var json = await new DocumentWriter(opt).WriteToStringAsync(result.Data);
var json = JsonConvert.SerializeObject(
result.Data,
Formatting.Indented,
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
return Content(json, "application/json");
}
谢谢