graphql-middleware icon indicating copy to clipboard operation
graphql-middleware copied to clipboard

Be able to blacklist queries/mutations

Open drager opened this issue 6 years ago • 2 comments

Hey, thanks for a great library!

I was wondering if it's possible to blacklist instead of whitelisting queries/mutations? I.e. this is how we do it today:

export const authMiddleware = {
  Query: {
    getUsers: isAuthenticated,
  }
}

Where isAuthenticated is applied for the getUsers query. However, now I need to add every single query in here or do the following:

export const authMiddleware = {
  Query: isAuthenticated,
}

which applies it to all queries. However, I want some queries to be able to get without being authenticated. It would be nice if you could do something like:

export const authMiddleware = {
  Query: isAuthenticated,
  except: ['getPublicProfile', 'getBlogPost']
}

Or is this possible in any way at the moment?

drager avatar Sep 03 '19 05:09 drager

I am afraid there's no obvious solution for that in graphql-middleware, at least nothing from the top of my head, but you could check out graphql-shield.

maticzav avatar Sep 03 '19 08:09 maticzav

Alright, thanks for the answer! That's too bad. It's easy to forgot to add the middleware function to one query so it would have been nice if it existed.

drager avatar Sep 04 '19 05:09 drager