Skip to content

Commit 9d53564

Browse files
plebmderriey
andauthored
Adds resolve custom logger to graphqlOperationLoggingPlugin (#150)
* feat(graphql-operation-logging-plugin): adds resolve custom logger * bump package version # Conflicts: # package.json * Update src/plugins/graphql-operation-logging-plugin.ts Co-authored-by: Mickaël Derriey <[email protected]> --------- Co-authored-by: Mickaël Derriey <[email protected]>
1 parent 5d685b4 commit 9d53564

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@makerx/graphql-apollo-server",
3-
"version": "1.5.1",
3+
"version": "1.6.0",
44
"private": false,
55
"description": "A set of MakerX plugins for Apollo Server",
66
"author": "MakerX",

src/plugins/graphql-operation-logging-plugin.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export interface GraphQLOperationLoggingPluginOptions<TContext extends GraphQLCo
5151
* Can be used to augment the log entry with additional properties
5252
*/
5353
augmentLogEntry?: (ctx: TContext) => Record<string, any>
54+
/**
55+
* Can be used to resolve a custom logger for the plugin
56+
*/
57+
resolveCustomLogger?: (context: TContext) => TLogger
5458
}
5559

5660
/**
@@ -68,6 +72,7 @@ export function graphqlOperationLoggingPlugin<TContext extends GraphQLContext<TL
6872
adjustVariables,
6973
adjustResultData,
7074
augmentLogEntry,
75+
resolveCustomLogger,
7176
}: GraphQLOperationLoggingPluginOptions<TContext, TLogger> = {}): ApolloServerPlugin<TContext> {
7277
return {
7378
contextCreationDidFail: async ({ error }) => {
@@ -80,7 +85,10 @@ export function graphqlOperationLoggingPlugin<TContext extends GraphQLContext<TL
8085
ctx: GraphQLRequestContextWillSendResponse<TContext>,
8186
subsequentPayload?: GraphQLExperimentalFormattedSubsequentIncrementalExecutionResult,
8287
) {
83-
const { started, logger } = contextValue
88+
const { started } = contextValue
89+
const { logger } = resolveCustomLogger
90+
? { logger: resolveCustomLogger(contextValue) }
91+
: contextValue
8492
const { operationName, query, variables } = ctx.request
8593
const isIntrospection = query && isIntrospectionQuery(query)
8694
if (isIntrospection && ignoreIntrospectionQueries) return

0 commit comments

Comments
 (0)