graphql-hive / graphql-hive/graphql-modules

Overriding Middlewares

Open
#1,775 5 comments 2 reactions 1 assignee Claimed by @kamilkisiela View on GitHub
Dominant language
TypeScript
Stars
1.3k
Forks
113
Avg merge
3h 36m
Merged PRs (30d)
1

Description

I'm loving the middlewares concept of GraphQL Modules!

I am struggling with something though, and wonder if anyone can help. I have a set of 20 or so queries in a module that all need to use an authorization middleware, but 2 of those queries need no middleware at all. I was hoping I could set the middleware for `*` and then override the 2 that don't need it like this:

```javascript
export default createModule({
id: 'my-module',
dirname: __dirname,
typeDefs,
resolvers,
middlewares: {
'*': {
'*': [authorization],
},
Query: {
noAuthQuery: [], // Override these with no middleware
}
},
});
```

However, that approach does not work since middlewares aren't coded to merge over one another. I could write out each "with auth" query and set them all to the middleware one by one, but that doesn't scale well and we're likely to forget one. I could also create a new module just for the 2 "without auth" queries, but that seems heavy since they all rely on the same types. Is there any other way I could accomplish my goal?

Thanks!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.