How to add middleware to apollo-server-micro in nextjs api routes?

Hi fellow developers

I’m currently working on a nextjs project where we use nextjs api routes combined with apollo-server-micro. I would like to whitelist a few queries and block the rest. To do this I need to be able to read the query from the request through a middleware. Something like below will be very helpful.

nextjs-api-route ----> (middleware) ----> apollo-server-micro

My plan is to read the query from the request in the middleware and block the query if its not in the allowed queries list.

apollo-server-express seems to be having this but it doesn’t provide the createHandler() function to integrate with nextjs.

I’d really appreciate any kind of help regarding this,