-
Notifications
You must be signed in to change notification settings - Fork 5
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
#102 into [email protected] 🐘 add logger support #131
Merged
Merged
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
155955e
#102 🐘 logger WIP
RiceWithMeat 87a33bd
Merge branch '#128' into #102
RiceWithMeat da5e3f0
#102 🐘 logger WIP
RiceWithMeat 105cced
#102 🐘 add logger in createRestMockServer and createGraphQLMockServer…
RiceWithMeat 1251aed
#102 🐘 loggers rework
RiceWithMeat c427ea0
#102 🐘 logger rework
RiceWithMeat 7344d74
Merge branch 'main' into #102
RiceWithMeat 3f7ce6d
Merge remote-tracking branch 'refs/remotes/origin/main' into #102
RiceWithMeat 95a29c1
#102 🐘 another logger rework
RiceWithMeat 8f51139
#102 🐘 simplify logger logic, add log function in interceptor params,…
RiceWithMeat 2973218
#102 🐘 remove loggers field in configs, rework filterTokenValues helper
RiceWithMeat 219b847
#102 🐘 add tests, add readme, move formatTokenValues into helper
RiceWithMeat 87367e4
#102 🐘 fix types in readme
RiceWithMeat ac14df2
#102 🐘 rename requestInfoMiddleware -> contextMiddleware, contextMidd…
RiceWithMeat ae46d1d
#102 🐘 remove useless type
RiceWithMeat 3276961
#102 🐘 remove enabled flag for logger
RiceWithMeat 33d52f5
#102 🐘 remove enabled flag for logger in readme
RiceWithMeat dc32ec2
#102 🐘 simplify logger types, allow use graphql tokens only in global…
RiceWithMeat 26275a2
#102 🐘 add graphQLQuery token, rename types and helpers
RiceWithMeat 179e1fa
#102 🐘 fix Interceptors type, remove logger object options for body, …
RiceWithMeat 98ec2e9
#102 🐘 rename type LoggerTokensToTokenOptions -> LoggerTokensToLogger…
RiceWithMeat 6c501f4
#102 🐘 fix readme and test for logger, swap Data and Api generics in …
RiceWithMeat 53ff177
#102 🐘 move spyOn for Date.now from test into describe
RiceWithMeat 02a09c0
#102 🐘 make tokens and rewrite optional in readme
RiceWithMeat a0542c0
#102 🐘 rename tokens parameter to options for log function
RiceWithMeat 1ab247e
#102 🐘 rename objectOptions -> nestedOption, fix comments in readme
RiceWithMeat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/core/middlewares/contextMiddleware/contextMiddleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { Express } from 'express'; | ||
|
||
import { getGraphQLInput, parseQuery } from '@/utils/helpers'; | ||
import type { GraphQLEntity, GraphQLOperationName, GraphQLOperationType } from '@/utils/types'; | ||
|
||
declare global { | ||
namespace Express { | ||
export interface Request { | ||
id: number; | ||
timestamp: number; | ||
graphQL: { | ||
operationType: GraphQLOperationType; | ||
operationName: GraphQLOperationName; | ||
variables?: GraphQLEntity<'variables'>; | ||
} | null; | ||
} | ||
} | ||
} | ||
|
||
export const contextMiddleware = (server: Express) => { | ||
let requestId = 0; | ||
|
||
server.use((request, _response, next) => { | ||
requestId += 1; | ||
request.id = requestId; | ||
|
||
request.timestamp = Date.now(); | ||
|
||
const graphQLInput = getGraphQLInput(request); | ||
const graphQLQuery = parseQuery(graphQLInput.query ?? ''); | ||
|
||
if (graphQLInput.query && graphQLQuery) { | ||
request.graphQL = { | ||
operationType: graphQLQuery.operationType as GraphQLOperationType, | ||
operationName: graphQLQuery.operationName as GraphQLOperationName, | ||
RiceWithMeat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
variables: graphQLInput.variables | ||
}; | ||
return next(); | ||
} | ||
|
||
request.graphQL = null; | ||
return next(); | ||
}); | ||
}; |
2 changes: 1 addition & 1 deletion
2
src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не хватает тестов на этот файл