GraphQL logging support #490
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the ability for GraphQL requests to be logged via the
LoggingInterceptor.Description
Nest provides a base
ExecutionContextthat allows for REST and GraphQL apps to be written with similar constructs. To obtain req and res metadata (headers, status, etc.) about a GraphQL request, one must first create aGqlExecutionContextfrom the baseExecutionContext.Via this pr, if a request is determined to be a GraphQL, a
GqlExecutionContextis created and metadata is obtained and logged in the same format as a REST request.While this gets the "job done", I have a number of issues with this implementation:
@nestjs/graphqldependencyTo differentiate between REST and GrapQL requests, a dependency(via a peerDependency) on
GqlContextTypefrom@nestjs/graphqlis required. I see this as problematic because most of the current users of theLoggingInterceptorwill not have this within their project. It doesn't make much sense to require rest users of this lib to install@nestjs/graphqljust to use the existing functionality.reqandresparameterTo obtain the
reqandresobjects from the gqlContext, you must configure your GraphQL module (see apollo-server-context. This isn't as big of an issue as 1 IMO as passing in req and res to the context is very standard. I have also added error handling to this.I could use some advice on point 1. Perhaps it is advisable to create a separate
GqlLoggingInterceptorclass within this package? Or perhaps I can do some work with the imports and package.json deps to negate this.Motivation and Context
This is not a required change but it solves the issue of not being able to use this package for GraphQL apps!
#489
Types of changes