statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
31 stars 1 forks source link

GraphQL middlewares before CacheResponse #978

Open dominikradl opened 1 year ago

dominikradl commented 1 year ago

It would be nice to be able to configure GraphQL middlewares that run before CacheResponse.

A use case would be a simple token authentication middleware. You would want to verify the token before you return a cached result. Currently, CacheResponse is always registered first: https://github.com/statamic/cms/blob/b5aeb0f0f57f5ecd0b62d11395eb5f81ea4bcc15/src/GraphQL/DefaultSchema.php#L76-L83

My current workaround is to disable caching in the config and then register a custom copy of \Statamic\GraphQl\Middleware\CacheResponse::class that utilizes DefaultCache after my middleware again, but that's obviously far from best practice.

Maybe we should expose the whole middleware array like routes?