'How to inject a value via middleware into a graphql query body (prisma-typegraphql)?

I am currently using prisma-typegraphql for generating a schema and it's props.

Problem: Is there a way to write a middleware that accesses a value from an arbitrary source, then injects that into the graphql-query arguments? It should be passed to the resolver in a way that makes it seem like the data has been in the query from the start and no modification to the resolver is necessary.

More info Let's say I have three models, one is Client, one is Project and one is User. The Project has a relationship to the client via its id, identifying the client the project belongs to, same for the user

model Client{
   id
   name
   etc...
}

model User{
   id
   name
   clientId / client
   etc...
}


model Project{
   id
   title
   clientId / client
   etc...
}

I don't want the clientId from the frontend via query, instead I intend to verify the user making the request and then get the clientId from that user. Currently my Auth Middleware does verify the user and then passes the user object along in the context. However, due to the generated nature of typegraphql-prisma resolvers, I cannot use the context to inject the data into the resolver without extending every single resolver.

I'd much rather inject the value I want into the graphql query before it reaches the resolver, so the resolver has no idea something changed and processes the query as intended.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source