Applying Middleware

When it comes to applying middleware, we’ve got two different approaches available to us. Sometimes you have middleware that you want to apply to very specific fields, or even just one field. A logout mutation, for example, might use middleware to mutate the context, removing the current user.

Other times, you want to ensure that a particular middleware is always applied to every field in a certain object, or every field that has a particular name and return type. This is critical for something like authorization, where you want to protect against a programmer forgetting to specify that a field should be secured.

Absinthe provides two main approaches to handle these types of scenarios, which we’ll examine in turn.

Macro Approach ...

Get Craft GraphQL APIs in Elixir with Absinthe now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.