Created
May 10, 2018 15:40
-
-
Save akoenig/fc1b30cff3782aa3c5647df38c240312 to your computer and use it in GitHub Desktop.
GraphQL: Hand rolled middleware mechanism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const aFieldResolver = (parent, args, context, info) => "beeeeeeeeep"; | |
const myCustomMiddleware = async (parent, args, context, info) => { | |
// Will be executed before the resolver | |
}; | |
const middleware = (middlewares, resolver) => async (...args) => { | |
for (const middleware of middlewares) { | |
await middleware(...args); | |
} | |
return resolver(...args); | |
}; | |
const Query = { | |
aField: middleware([myCustomMiddleware], aFieldResolver) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment