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

feat: support graphql in request interceptor #14

Merged
merged 2 commits into from
Jan 16, 2024
Merged

Conversation

MiffyLiye
Copy link
Member

Description

  • Support GraphQL in request interceptor
  • When request is not RESTful or GraphQL, do nothing in request interceptor

Issue ticket number and link

https://github.com/Wiredcraft/nestjs-boilerplate/issues/192

@@ -10,7 +13,14 @@ import { AppController } from './app.controller';
excludeReqPath: '/health',
shortBodyLength: 100,
}),
GraphQLModule.forRoot<ApolloDriverConfig>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having a question on what is the best place to define and import the GraplqlModule? I was defining it in the CommonModule like what we do for CouchbaseModule, and then import this Module in the other modules that need it. Should we do the same here instead of directly define its initialization on the AppModule?

Copy link
Member Author

@MiffyLiye MiffyLiye Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move the discussion to the original issue https://github.com/Wiredcraft/nestjs-boilerplate/issues/192
as a test setup, I prefer to keep it slim: register graphql module, controller and resolver in app module.

package.json Show resolved Hide resolved
const url = req.url;
const route = req.route.path;
const url = req.originalUrl;
const route = context.getType() === 'http' ? req.route.path : req.baseUrl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.getType() repeats multiple times, is it better to separate the extracting req/res from the context into another place so that intercept only takes care higher level logging tasks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved extracting req / res in a function in a new commit.

@xavierchow
Copy link
Member

Support GraphQL in request interceptor

I'm not quite familiar with GraphQL, do we have an alignment about what to log for a GraphQL request?
Most information is in the payload(request / response body), but it will be too verbose to record the whole body, no? @MiffyLiye

@MiffyLiye
Copy link
Member Author

do we have an alignment about what to log for a GraphQL request?
Most information is in the payload(request / response body), but it will be too verbose to record the whole body, no?

Currently logs same fields as restful request,
the request / response body converts to short-body with max length 100,
whether log full details of the query will need alignment.

@MiffyLiye MiffyLiye changed the title feat: support graphql in request interceptor [WIP] feat: support graphql in request interceptor Apr 26, 2023
@xavierchow
Copy link
Member

hold on until we have some progress about https://github.com/Wiredcraft/nestjs-boilerplate/issues/192#issuecomment-1523184902.

Copy link
Member

@xavierchow xavierchow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logging format of graphql request body can be optimized with other PRs.

@MiffyLiye MiffyLiye changed the title [WIP] feat: support graphql in request interceptor feat: support graphql in request interceptor Jan 16, 2024
@MiffyLiye
Copy link
Member Author

in short term, use excludeReqPath to skip graphql requests in interceptor, and add logger in each graphql resolver class.
in long term, a graphql apollo server plugin should be added to log graphql request / response.

@MiffyLiye MiffyLiye merged commit 89f3a44 into master Jan 16, 2024
1 check passed
@MiffyLiye MiffyLiye deleted the feat-graphql branch January 16, 2024 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants