question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@Context decorator undefined for property resolvers

See original GitHub issue

I’m submitting a…


[x] Regression 

Current behavior

Given the following GraphQL resolver:

@Resolver('SearchResponse')
export class ShopFulltextSearchResolver implements Omit<BaseSearchResolver, 'reindex'> {
    constructor(private fulltextSearchService: FulltextSearchService) {}

    @Query()
    async search(
        @Ctx() ctx: RequestContext,
        @Args() args: SearchQueryArgs,
    ): Promise<Omit<SearchResponse, 'facetValues'>> {
        return this.fulltextSearchService.search(ctx, args.input);
    }

    @ResolveProperty()
    async facetValues(
        @Ctx() ctx: RequestContext,
        @Context() context: any,
    ): Promise<Array<{ facetValue: FacetValue; count: number }>> {
        return this.fulltextSearchService.facetValues(ctx, context.req.body.variables.input);
    }
}
  • the search method resolves a top-level query
  • the facetValues method resolves a property of the SearchResponse type.

The context variable is undefined in the facetValues method.

Expected behavior

The context variable should contain the GraphQL context object, including the underlying express req object which I am making use of in the method body.

Note that this worked in Nest v6.0.2. After upgrading today to v6.0.5 it stopped working. Also, the @Context decorator appears to work as expected for top-level queries. Only property resolvers are broken.

Minimal reproduction of the problem with instructions

I put together this repo, which does not exactly reproduce the behaviour in my app but is close. In this case, the context object is empty, rather than undefined: https://github.com/michaelbromley/nest-issue-191-repro

Environment


Nest version: 6.0.5, graphql v6.0.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilmysliwieccommented, Apr 2, 2019

Could you please check with @nestjs/graphql@6.0.5? Thanks for reporting

0reactions
lock[bot]commented, Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolvers | NestJS - A progressive Node.js framework
decorator. In this example, we defined a query handler to get the author object based on the id sent in the request. To...
Read more >
Writing query resolvers | Full-Stack Quickstart
The resolver function signature ; context, This object is shared across all resolvers that execute for a particular operation. Use this to share...
Read more >
applyResolversEnhanceMap not adding custom ...
I'm using the typegraphql-prisma package and am trying to apply custom decorators to my generated resolvers to no avail.
Read more >
How to use the @nestjs/graphql.Context function in ...
To help you get started, we've selected a few @nestjs/graphql.Context examples, based on popular ways it is used in public projects.
Read more >
type-graphql/Lobby - Gitter
ERROR: TypeError: Cannot read property 'getObjectType' of undefined at ... Error: No provided object type in '@Resolver' decorator for class ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found