How do I find which fields need to be resolved from `info: GraphQLResolveInfo`?

Let’s say graphql type definitions is

type Post {
    id: ID!
    tags: Tag
}

type Tag {
    id: ID!
    name
    parentTag: Tag
}

type Query {
    lastPost: Post
}

and the user query is

{
   query {
       lastPost {
           tags {
               name
               parentTag {
                   name
               }
           }
       }
   }
}

and the Query.lastPost resolver will return

{
   "id": 1,
   "tagIds": [5,6,7]
}

How do I extract what’s missing from inside the Query.lastPost and get the result below?

const missingFields = `
           tags {
               name
               parentTag {
                   name
               }
           }
`;

Do you mind sharing why you’re trying to gather that information? My instinct is to steer you away from that question unless you have a very specific reason to do that.

A more conventional approach for your resolvers might look something like this. Note that lastPost doesn’t return tag IDs since it really shouldn’t be concerned with whether or not tags was requested or not. Now tags is responsible for loading all the tags that belong to a post.

Does this make sense? Is this what you’re looking to accomplish?

  resolvers: {
    Query: {
      lastPost() {
        return { id: 1 };
      },
    },
    Post: {
      tags(parentValue) {
        // const tagsForPost = lookup tags by parentValue.id (post ID)
        return [{id: 1, name: "tag1"}]
      }
    }
  },

Also there’s an error in your SDL, I assume you meant tags: [Tag!] (it’s currently not a list type in your snippet)

GitHub - apollosolutions/federation-subscription-tools: A set of demonstration utilities to facilitate GraphQL subscription usage alongside a federated data graph already does that. I’m trying to what it does, without this library.