graphql / express-graphql

Create a GraphQL HTTP server with Express.
MIT License
6.34k stars 538 forks source link

Middleware within express-graphql? #208

Closed i-am-tom closed 7 years ago

i-am-tom commented 7 years ago

Hello! First of all, thank you for this project - it's great!

Secondly, I think https://github.com/graphql/express-graphql/issues/113 is one solution to my problem, but I'm hoping there's another in the mean time...

I've written my app using free monad machinery with my own little DSL. So, for a route that is meant to return a String, the route actually produces a Free[DB, String]. What I'd like to do is be able to set some global middleware just before the stage that says "the types don't match up" that can run the route's output through an interpreter to get out what's needed (most likely a Promise[GraphQLError, String]).

tl;dr: can middleware be placed after execution of a resolver and before validation?

Thanks in advance :)

wincent commented 7 years ago

At the moment, I don't think there's a way to do this, short of forking the project. I think, like you say, that #113 will be the eventual answer, so I'm going to close this one as a duplicate. Thanks for your question!