GraphQL Middleware for query of nested data

System Information
  • Strapi Version: 4.20.4
  • Operating System: Linux (docker container node:18)
  • Database: MySQL
  • Node Version: 18
  • NPM Version:
  • Yarn Version:

I have content types in my system for Lessons and Answers. Each Lesson has many Answers and each Answer is saved by a specific user. I want to write a middleware for GraphQL to limit queries to only return Answers for the logged-in user. I found documentation for is-owner and got that to work when querying each content type directly. I would also like it to apply when I query a lesson and populate the answers attribute.

However, I’m trouble finding how to name the resolverConfig to catch that sub-query. I’m able to capture the Lesson query and if I query Answers directly, I can capture that. But when populating the answers attribute on Lessons, it doesn’t hit either of those middlewares.

Here are the two different queries I’m trying to run:

query Lesson {
    lesson(id: "1") {
        data {
            id
            attributes {
                name
                answers {
                    data {
                        id
                    }
                }
            }
        }
    }
}
query Answers {
  answers {
    data {
      id
      attributes {
        answer
        lessonQuestionId
        user {
          data {
            id
          }
        }
      }
    }
  }
}

These are the resolversConfigs that are set in /src/index.js as per the documentation:

'use strict';

module.exports = {
  register(/*{ strapi }*/) {
    const extensionService = strapi.plugin('graphql').service('extension');

    extensionService.use({
      resolversConfig: {
        'Query.lesson': {
          middlewares: [
            async (next, parent, args, context, info)  => {
              strapi.log.info('Query.lesson query'); // triggered only by lesson query
              return next(parent, args, context, info);
            }
          ]
        },
        'Query.answers': {
          middlewares: [
            async (next, parent, args, context, info)  => {
              strapi.log.info('Query.answers query'); // triggered only by answers query
              return next(parent, args, context, info);
            }
          ]
        },
        'Query.answer': {
          middlewares: [
            async (next, parent, args, context, info)  => {
              strapi.log.info('Query.answer query'); // never triggered
              return next(parent, args, context, info);
            }
          ]
        },
      }
    })
  },
  bootstrap(/*{ strapi }*/) {},
};

I can’t seem to find the right resolver name to use to capture the query for the lesson answers. I’ve tried Query.lessonAnswer, Query.lesson.answers, Query.lesson.data.attributes.answers, answers, and maybe some other variations of that. I would think that the way that GraphQL will chain together resolvers (from my limited understanding of it), it would hit Query.answers after Query.lesson when running my lesson query.

Any help on finding how to write this middleware and limit the results