Graphql-yoga: New Feature: Pluggable Middleware (for AAA among other)

Created on 30 Nov 2017  路  12Comments  路  Source: dotansimha/graphql-yoga

This would be a great nice to have,

and it could narrow to something as simple as hooks during the instantiation of the express server.

Most helpful comment

@giautm would be great if you could create a PR with a new example application using this feature 馃帀

All 12 comments

I think there is a good example about authentication via directives: https://github.com/chenkie/graphql-auth

interesting...

I was about to propose yoga-middlewares, but obviously implementing authentication via the resolvers is another option. I guess, it depends if yoga is a lean or fullstack framework.

Went over your code... then found this issue https://github.com/chenkie/graphql-auth/issues/2
That's a real problem... and a waste of resources. not to mention the side-effects for mutations.

This leads me to believe that yoga could benefit from a better middleware implementation, in fact something like this https://github.com/scaphold-io/graphql-extended/blob/master/src/middleware/Middleware.ts

which allows the implementation of any type of middleware, not just AAA

@orefalo: We can create two directives like @authBefore(roleIds: [string]) and @authAfter(roleIds: [string]) to do same thing as middlewares.
roleIds is a optional variable, if set user must log in and has least one of the roles

@giautm I would gladly look at some samples ;-) No idea how to get it done.

Actually found this project, which seems to be in perfect alignment

https://github.com/thebigredgeek/apollo-resolvers

Video's really good
https://www.youtube.com/watch?v=xaorvBjCE7A

@orefalo: i have tried apollo-resolvers, i don't want wrap all of resolvers with a function. It look so ugly.

@orefalo: I posted a implement at here. Please take a look. Tks. :)

I opened PR at here to bring it to graphql-tools: https://github.com/apollographql/graphql-tools/pull/518

Directive can use as before & after resolver middlewares :D.

Hey! That PR really merged and release with version 2.13.0. So we can close this issues

cool! thank you @giautm

@giautm would be great if you could create a PR with a new example application using this feature 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

checkmatez picture checkmatez  路  5Comments

marktani picture marktani  路  5Comments

kv-pawar picture kv-pawar  路  3Comments

SebastianEdwards picture SebastianEdwards  路  4Comments

lautiamkok picture lautiamkok  路  4Comments