Skip to content

WIP: feat(server): add gql middleware to server (poc)

Yannis Barlas requested to merge graphql-middleware into master

This is more of a proof of concept than actual working code, so don't merge. :)

We could, with very minimal code (5 lines of code) and no backward compatibility issues add graphql middleware support to pubsweet server.
My code here assumes a new dependency, so check the docs for it as well.
This would essentially allow each project to insert their own middleware just as they add components, and run some code before or after a resolver (or both).

Needless to say, there are plenty of use cases for this. Off the top of my head:

  • Authorization: Auth intercept when calling a resolver or filter the results. Hindawi could also isolate their auth middleware even further (there would be no need to wrap resolver exports).
  • Notifications: Notifications like email etc could be moved out of resolvers and just ran after a successful resolver.
  • Subscriptions: After a resolver, send out relevant subscription events.

Basically any resolver code that runs a check before it starts or performs a side-effect could be moved into a such a module.
I think that having middleware will provide all of us with a very nice and neat isolation of concerns for our server code.

Merge request reports