显示-父类型
人-子类型
一个节目可以有很多人。我想将show类型的每个'personId'作为其子类型Person的参数传递,如下所示:
{
shows
{
showId
personId
person(personId: <I_NEED_TO_PASS_THE_personId_ABOVE_HERE>)
{
name
}
}
}
我可以知道如何在“人员”字段中访问“人员编号”字段(同级)的值吗?
public class ShowType : ObjectGraphType<Core.Show>
{
public ShowType(
IPersonRepository PersonRepository,
IHttpContextAccessor accessor)
{
Field(a => a.ShowId);
Field(a => a.PersonId); // PERSONID_VALUE
Field<PersonType>(
"Person",
arguments: new QueryArguments(
new QueryArgument<IdGraphType> { Name = "PersonId" }
),
resolve: context =>
{
var PersonId = context.GetArgument<string>("PersonId");
return PersonRepository.GetPerson(accessor.HttpContext, <I_NEED_PERSONID_VALUE_DIRECTLY_HERE_OR_THROUGH_ARGUMENTS>);
}
);
}
}
请告知如何实现此目标。
答案 0 :(得分:0)
此问题已解决。感谢SUNMO-How to access arguments in nested fields in ASP.NET Core GraphQL
public class ShowType : ObjectGraphType<Core.Show>
{
public ShowType(
IPersonRepository PersonRepository,
IHttpContextAccessor accessor)
{
Field(a => a.ShowId);
Field(a => a.PersonId);
Field<PersonType>(
"Person",
resolve: context =>
{
return PersonRepository.GetPerson(accessor.HttpContext, context.Source.PersonId);
}
);
}
}