type-graphql
type-graphql copied to clipboard
Documentation for `@Info` decorator
When trying to figure out how to get information about a request (like which fields are being requested), I searched through documentation but didn't find anything. On Stack Overflow I found out about the @Info
decorator, but I'm not seeing where that's described.
Is information about @Info
hard to find or is it undocumented?
Maybe it's undocumented, I bet 1% of users need access to the GraphQLResolveInfo
.
@MichalLytek You need the @Info decorator, when you implement your own caching. I have several projects, where caching is implemented in the datasources, so you need to handover info.cacheControl.cacheHint
from the query to your datasource when handling queries.
I just assumed the @Info decorator is there and works as @context and @args, so I created a interface like I did for @context and it worked as expected (you can of course also directly use the ResolveInfo class: @Info() info: GraphQLResolveInfo,
).
For new or unexperienced users and to be complete with the GraphQL implementation documentations (e.g. Apollo), a documentation update would be highly appreciated :)
@itpropro, did this actually work for you? I'm unable to get it to properly work without the @Directive
decorator on the response, which seems unnecessary.
For example:
@Resolver()
export class AllPostsResolver {
@Query(() => AllPostsResponse)
async AllPosts(
@Arg('category', () => String, { defaultValue: null, nullable: true })
@Info() info: GraphQLResolveInfo,
) {
// cache response for 10 minutes
info.cacheControl.setCacheHint({ maxAge: 600, scope: CacheScope.Public });
// ...get posts below...
I would have expected that to work, but it does not.
How can I get the GraphQLResolveInfo
object inside a parameter or method decorator?
@arthurfiorette
{ root, args, context, info }