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.

Resolver Guards: Cannot get request data from ExecutionContext

See original GitHub issue

I’m submitting a…


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

executionContext.switchToHttp().getRequest() inside Guard return null, when I hit resolver using Graphiql (GraphQL IDE)

Expected behavior

executionContext.switchToHttp().getRequest() should return http request data

Minimal reproduction of the problem with instructions

@Injectable()
export class RolesGuard implements CanActivate {
  constructor(
    private readonly reflector: Reflector,
  ) {}

  async canActivate(context: ExecutionContext): Promise<boolean> {
    try {
      const request = context.switchToHttp().getRequest();

Environment


Nest version: 5.3.6

 
For Tooling issues:
- Node version:  v10.9.0
- Platform:  MAC

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
EricKitcommented, Feb 17, 2019

While closed, the documentation isn’t great. There is nothing the explains what you’ll get back from getContext() of a GqlExecutionContext.

1reaction
kamilmysliwieccommented, Sep 17, 2018

@WonderPanda see https://docs.nestjs.com/techniques/authentication GraphQL (there is an example how to achieve that)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Execution context | NestJS - A progressive Node.js framework
ExecutionContext class​​ The getHandler() method returns a reference to the handler about to be invoked. The getClass() method returns the type of the...
Read more >
unable to get cookies from ExecutionContext - Stack Overflow
I wanted to apply Guard only to a specific Resolver, so I used UseGuard instead of global middleware. Did my approach go wrong?...
Read more >
cannot set headers after they are sent to the client nestjs
The error "Error: Can't set headers after they are sent." means that you're already in the Body or Finished state, but some function...
Read more >
Guards with HttpModule : r/Nestjs_framework - Reddit
Guys, I'm implementing a bff with Nestjs that communicates with an api made in java. Then I created this guard: export class JwtAuthGuard ......
Read more >
Node.js v19.3.0 Documentation
require.cache; require.extensions; require.main; require.resolve(request[, ... Since Node.js 8.0.0, exposure of memory cannot occur because the data is ...
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