A schema wrapper for GraphQL that lets you run arbitrary code before or after resolver execution using middleware functions.
GraphQL Middleware is a library that allows developers to split GraphQL resolvers into middleware functions. It wraps a GraphQL schema to run arbitrary code before or after resolver execution, enabling cross-cutting concerns like logging, authorization, and input validation without cluttering resolver logic.
GraphQL API developers using Node.js who need to implement reusable logic across multiple resolvers, such as authentication, logging, or performance monitoring.
It provides a clean, declarative way to manage middleware in GraphQL servers, compatible with any schema and offering fine-grained control over resolver execution, unlike directives which mix schema with functionality.
Split up your GraphQL resolvers in middleware functions
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows code to run before and after resolvers with full access to arguments and results, enabling logging, validation, and modification, as demonstrated in the 'onion' principle example with logInput and logResult.
Works with any GraphQL schema and integrates with tools like Apollo Server, ensuring it can be added to existing projects without schema changes, as shown in the standalone usage example.
Middleware can be applied to the entire schema, specific types, or individual fields using an intuitive API, improving code organization and reuse, detailed in the API section.
Supports GraphQL fragments to specify data requirements for middleware, ensuring correct execution even with partial client queries, as explained in the fragments documentation.
Version 3.0.0 stopped wrapping introspection queries, and 5.0.0 removed built-in support for GraphQL Yoga, indicating instability and potential migration efforts for users.
The 'onion' principle adds layers to resolver execution, which can complicate debugging and performance tracing, as mentioned in the overview with nested middleware calls.
Support for tools like GraphQL Yoga is conditional on their maintenance, leading to integration risks if dependencies become unmaintained, noted in the README's version notes.