Can you force a HotChocolate resolver to be run off another resolver?

29 views Asked by At

I'm looking for a way to make HotChocolate load data from a complex type in the same way [IsProjected] loads data from a base type. Take the following situation.

class Person
{
  public Guid Uuid {get; set;}
  [IsProjected(true)]
  public string Name { get; set; }
  public Work CurrentJob { get; set; }
  public Education MaxEducationalLevel { get; set;}

  public string CareerDescription
  {
    get => $"{Name} works for {CurrentJob.Description} and has a {MaxEducationalLevel.Description}"
  }
}

class Work
{
  public Guid Uuid {get; set;}
  [IsProjected(true)]
  public string EmployerName {get;set;}
  [IsProjected(true)]
  public string Title {get;set;}
  public string Description { get => $"{EmployerName} as a {Title}" }
}

class Education 
{
  public Guid Uuid {get; set;}
  [IsProjected(true)]
  public string SchoolName {get; set;}
  [IsProjected(true)]
  public string DegreeName {get; set;}
  public string Description { get => $"degree from {SchoolName} in {DegreeName}" }
}

In order to get CareerDescription to output correctly from graphql I'd have to do a call like:

people{ careerDescription, currentJob { uuid }, maxEducationalLevel { uuid }    }

The uuids are not particularly important, but I would have to call some field on currentJob and maxEducationalLevel in order for HotChocolate to recognize the IsProjected on the other fields. Only then can those fields be used by the careerDescription resolver.

What I would like to be able to do is to just do a call like

people{ careerDescription }

and have HotChocolate recognize that the data from currentJob and maxEducationalLevel needs to be fetched from the db as well.

Note: I am working with pre-existing tables, and I cannot change the table structure. So I cannot use any answer that suggests re-structing the DB, only answers that can solve the issue through code. I am working with HotChocolate 12 and Efcore 6 in case that helps.

0

There are 0 answers