title: Invoke resolvers of fields on nested execution levels in NestJS GraphQL
body: <p>I'm building a GraphQL API in NestJS supporting queries for nested objects, but I don't know how to invoke existing resolvers on an object-type from a parent resolver's <code>@ResolveField()</code> instead of having to resolve every nested field and object-type from <code>@ResolveField</code>.</p>
  <p>I want to do a query on a person with a pet with a toy to get the color of the toy.</p>
  <p>I.e. I want to be able to resolve the following query in the best way possible:</p>
  <pre><code>{
    person(id: &quot;id123&quot;) {
      name
      petId
      pet: {
        toy: {
          color
        }
      }
    }
  }
  </code></pre>
  <p>I have the following object types defined as entities:</p>
  <p><strong>Person entity:</strong></p>
  <pre class="lang-js prettyprint-override"><code>import { ObjectType, Field } from '@nestjs/graphql';
  import { Pet } from 'src/pet/entities/pet.entity';
   
  
  @ObjectType()
  export class Person {
    @Field(() =&gt; String)
    id: string;
  
    @Field(() =&gt; String)
    name: string;
  
    @Field(() =&gt; String)
    petId: string;
  
    @Field(() =&gt; Pet)
    pet: Pet;
  }
  </code></pre>
  <p><strong>Pet entity:</strong></p>
  <pre class="lang-js prettyprint-override"><code>import { ObjectType, Field } from '@nestjs/graphql';
  import { Toy } from 'src/toy/entities/toy.entity';
   
  
  @ObjectType()
  export class Pet {
    @Field(() =&gt; String)
    id: string;
  
    @Field(() =&gt; String)
    species: string;
  
    @Field(() =&gt; String)
    toyId: string;
  
    @Field(() =&gt; Toy)
    toy: Toy;
  }
  </code></pre>
  <p><strong>Toy entity:</strong></p>
  <pre class="lang-js prettyprint-override"><code>import { ObjectType, Field } from '@nestjs/graphql';
  
  @ObjectType()
  export class Toy {
    @Field(() =&gt; String)
    id: string;
  
    @Field(() =&gt; String)
    color: string;
  }
  </code></pre>
  <p>Currently I resolve a person's <code>name</code> and <code>petId</code> using the decorator <code>@Query(() =&gt; Person, { name: &quot;person&quot; })</code> from my person <code>@Resolver</code>, and I resolve <code>pet</code> with <code>@ResolveField(&quot;pet&quot;, () =&gt; Pet)</code>. My problem is, that I don't know how to invoke the resolver of a Pet from within the <code>@ResolveField(&quot;pet&quot;, () =&gt; Pet)</code>. It seems natural, that I should be able to invoke a pet resolver to move on in the resolver tree instead of having to resolve pet as well as toy and every other sub-field from <code>@ResolveField(&quot;pet&quot;, () =&gt; Pet)</code> in the person resolver.</p>
  <p>Shouldn't GraphQL be smart enough to invoke resolvers of nested objecttypes on nested execution levels?
  Or should I really manually resolve the rest of the resolver tree from a <code>@ResolveField</code> decorated method?</p>
  <p>Every example I've found directly makes a call to the child object-type's service method instead of its resolver.
  Like <a href="https://docs.nestjs.com/graphql/resolvers#code-first-resolver" rel="nofollow noreferrer">here</a> where an Author's posts are resolved from <code>@ResolveField()</code> by calling <code>postsService.findAll()</code>.</p>
  <p>What can I do? Thanks in advance!</p>