-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mercurius + typegraphql + @Ctx() decorator #517
Comments
Is it an instance of MercuriusContext? How would I modify it? |
Thanks for asking, I have never used typegraphql, so I do not know. |
@jessekrubin - Try out NestJS. There is a Mercurius module and being Nest has a GraphQL code first approach almost the same as TypeGraphQL AND a modules system for DI, it is a step up from TypeGraphQL. https://docs.nestjs.com/graphql/quick-start Scott |
It is, yep
Are you referring to the type or the value (or both?)? |
Both |
@smolinari i might give it a look. I tried out nest a while ago and thought super over engineered and not very well documented. I adore fastify. Why do you like nest? Maybe I will give it another go... |
@jessekrubin - I like Nest, because it offers a modularization system (fashioned after Angular, but that is definitely not why I like it). So, this modularization helps the application be split up smartly for testing and scaling due to its DI container system. And, it is above and beyond Fastify. By that I mean, Nest can use Fastify (or Express) as the HTTP server basis, but Nest builds on top of the web servers and is much more about logic segregation. The fact it can use Fastify under the hood also means all the good plugins for Fastify will also work with Nest. Lastly, if you like how you can decorate stuff to make things happen, like in TypeGraphQL, then Nest is a smart addition in terms of the business logic side of your app, as you can also decorate your resolvers with pipes for validation, guards for auth, and interceptors for transformations, etc. Yes, there is a learning curve as there is with any framework, but once the understanding is there, any team member will have it easier in getting into the code (part of the scaling I mentioned above). If you are building something to last and grow with Enterprise grade quality, then needing a system like Nest will be an inevitable choice. Scott |
For the value, you can customise this with the For the type, there are two options I can think of (I'm not sure if it's possible to infer):
@Query(...)
async fileexists(@Arg('fspath') fspath: string, @Ctx() ctx: Context): Promise<boolean> {
return existsPromise(fspath);
}
declare module 'mercurius' {
export interface MercuriusContext {
...
}
}
@Query(...)
async fileexists(@Arg('fspath') fspath: string, @Ctx() ctx: MercuriusContext): Promise<boolean> {
return existsPromise(fspath);
} Hope that helps :) |
How do you get the type of the context when using mercurius with typegraphql where a resolver has a ctx param such as:
The text was updated successfully, but these errors were encountered: