2

Shows - Parent Type

Person - Child Type

ONE show can have MANY persons. I want to pass each 'personId' from shows type as an argument to its child type Person as shown below:

{
  shows 
  {
    showId
    personId
    person(personId: <I_NEED_TO_PASS_THE_personId_ABOVE_HERE>) 
    {
      name
    }
  }
}

May I know how to access the value of PersonId Field (sibling) in the Person field please?

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>);
          }
        );
    }
}

Please advise how to achieve this.

MAK
  • 1,915
  • 4
  • 20
  • 44

1 Answers1

2

This has been solved. Thanks to 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);
          }
        );
    }
}
MAK
  • 1,915
  • 4
  • 20
  • 44