apollo-resolver-middleware
v1.0.0
Published
``` npm i apollo-resolver-middleware ```
Downloads
1
Maintainers
Readme
install
npm i apollo-resolver-middleware
usage
add middlewares in schema.js where resolvers defined
const applyResolverMid = require('apollo-resolver-middleware')
const typeDefs = gql`
type Query {
getData: Response
}
type Response {
success: Boolean
message: String
}
`
const resolvers = {
Query: {
getData: (parent, args, context, info) => {
return {
success: true,
message: ''
}
}
}
}
applyResolverMid(resolvers, 'Query.getData', (args, context, next) => {
// do something
return next()
})
module.exports = { typeDefs, resolvers }
api
applyResolverMid(resolvers, path, fn)
- resolvers: the apollo resolvers you defined
- path: specific resolver path
- fn: the middleware function
middleware
- the first tow arguments are
args
andcontext
from the graphql resolver - call
next
to excute the next middleware
middleware(args, context, next) {
return next()
}