maticzav / graphql-middleware

Split up your GraphQL resolvers in middleware functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option to support introspection queries

cappslock opened this issue · comments

I see that graphql-middleware intentionally doesn't run on introspection queries. This makes sense, but I have a use case where it's causing problems.

I am trying to manage database transactions at the middleware and context level. I create the transaction in the context factory (because I have dataloaders created in context that I want to provide the transaction to). The middleware then handles committing or rolling back the transaction based on whether the query was successful.

This works great except for the introspection query, because that query triggers context creation but not the middleware, resulting in transactions that are opened but never committed. I could fix this by creating and committing the transactions entirely in the middleware, but as I mentioned before I need the transaction available when creating the context.

So yeah, being able to opt in to this somehow would be helpful.

Hi @cappslock 👋 ,

Did you, by chance, find a way to work this issue out? We used to support wrapping introspection queries in the early versions, but then a new GraphQL version came out, which made it impossible to run promises in introspection query resolvers. That's why we decided to strip out that part to keep the code simpler.

Do you think that you could still solve your problem without promises?

Hi @maticzav, this was for an older project, but IIRC I ended up abandoning this approach. Sorry I don't recall more.

Won't hurt my feelings none if you decide to close this, I think I just wanted to report it so it was known :)

@cappslock, no worries! I am glad you've found a solution.