Skip to content
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

Documentation for @Info decorator #1200

Open
apoco opened this issue Feb 10, 2022 · 5 comments
Open

Documentation for @Info decorator #1200

apoco opened this issue Feb 10, 2022 · 5 comments
Labels
Community 👨‍👧 Something initiated by a community Documentation 📖 Issues about docs

Comments

@apoco
Copy link

apoco commented Feb 10, 2022

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?

@MichalLytek
Copy link
Owner

Maybe it's undocumented, I bet 1% of users need access to the GraphQLResolveInfo.

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Documentation 📖 Issues about docs labels Feb 10, 2022
@itpropro
Copy link

itpropro commented Feb 27, 2022

@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 :)

@1thrasher
Copy link

@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.

@arthurfiorette
Copy link

How can I get the GraphQLResolveInfo object inside a parameter or method decorator?

@MichalLytek
Copy link
Owner

@arthurfiorette
{ root, args, context, info }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Documentation 📖 Issues about docs
Projects
None yet
Development

No branches or pull requests

5 participants