Resolvers Composition Transform
The resolversComposition transform allows adding middleware to your existing resolvers.
yarn add @graphql-mesh/transform-resolvers-compositionHow 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#isAdminmodule.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)
}
}💡
For information about "bare" and "wrap" modes, please read the dedicated section.
Config API Reference
mode(type:String (bare | wrap)) - Specify to apply resolvers-composition transforms to bare schema or by wrapping original schemacompositions(type:Array of Object, required) - Array of resolver/composer to apply:resolver(type:String, required) - The GraphQL Resolver path Example: Query.userscomposer(type:Any, required) - Path to the composer function Example: ./src/auth.js#authComposer
Last updated on July 27, 2022