Docs / Transforms / Resolvers Composition Transform (deprecated) Resolvers Composition Transform (deprecated) GraphQL Mesh v0 documentation (superseded by v1): Improve your GraphQL resolvers with GraphQL Mesh Resolvers Composition Transform. Add middleware to your resolvers easily. Learn how now!
v1latest v0
This is the documentation for the old GraphQL Mesh v0 We recommend upgrading to the latest GraphQL Mesh v1.
Migrate to GraphQL Mesh v1 .
We don’t recommend to use this transform anymore!
The resolversComposition transform allows adding middleware to your existing resolvers.
npm yarn pnpm bun
npm i @graphql-mesh/transform-resolvers-composition yarn add @graphql-mesh/transform-resolvers-composition pnpm add @graphql-mesh/transform-resolvers-composition bun add @graphql-mesh/transform-resolvers-composition
How to use?
Add the following configuration to your Mesh config file:
transforms :
- resolversComposition :
mode : bare | wrap
compositions :
- resolver : 'Query.me'
composer : is-auth#isAuth
- resolver : 'Mutation.*'
composer : is-admin#isAdmin
module . exports = {
isAuth : next => ( root , args , context , info ) => {
// Check if Authorization header is present
if ( ! context.headers.authorization) {
throw new Error ( 'Unauthorized' )
}
return next (root, args, context, info)
}
}
Config API Reference
mode (type: String (bare | wrap)) - Specify to apply resolvers-composition transforms to bare schema or by wrapping original schema
compositions (type: Array of Object, required) - Array of resolver/composer to apply:
resolver (type: String, required) - The GraphQL Resolver path
Example: Query.users
composer (type: Any, required) - Path to the composer function
Example: ./src/auth.js#authComposer
← Replace Field Naming Convention →