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

Graphql Support for LoggingInterceptor #489

Open
agmoss opened this issue Jun 18, 2022 · 3 comments
Open

Graphql Support for LoggingInterceptor #489

agmoss opened this issue Jun 18, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@agmoss
Copy link

agmoss commented Jun 18, 2022

Currently, the LoggingInterceptor does not work with graphql. Internal calls to intercept, logNext, and logError use the base ExecutionContext from nest without first evaluating the current application context.

Accessors for the in-flight request object are different depending on the application context. For rest they look like:

const req: Request = context.switchToHttp().getRequest<Request>();
const res: Response = context.switchToHttp().getResponse<Response>();
const { method, url } = req;

as you have in logNext

In graphql it looks like

const method = context.getArgs()[2].req.method;
const url = context.getArgs()[2].req.url;

(at least this is the cleanest way I have been able to access these)

As such, the use of rest style of access yields the following logs when in the graphql context:

[LoggingInterceptor - undefined - undefined - undefined] Outgoing response - undefined - undefined - undefined 

Anyway, if you want to support gql with this interceptor I would be open to making a pr! Or perhaps I could add a new one that is specific for graphql.

This is a great assembly of nest utils!

@ccoeurderoy
Copy link
Contributor

Hey @agmoss,

Indeed, we do not handle graphQL for now but it could be nice to handle it. Unfortunately, I can't tell you when we can implement graphQL support.

I think we could create an option for graphQL, no need to create a new package. If you wish to, you can of course contribute and open a new PR to handle this 😁

@ccoeurderoy ccoeurderoy added the enhancement New feature or request label Jun 18, 2022
@agmoss
Copy link
Author

agmoss commented Jun 18, 2022

Sounds great @ccoeurderoy! I will take a stab at a pr. Cheers

@agmoss agmoss mentioned this issue Jun 21, 2022
3 tasks
@youngkiu
Copy link

I converted two components, LoggingInterceptor and HttpExceptionFilter for GraphQL, including test code.

https://github.com/youngkiu/nestjs-graphql-components/tree/feat/graphql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants