Skip to content

Commit 693531a

Browse files
committed
feat(graphql-operation-logging-plugin): adds resolve custom logger
1 parent d81acad commit 693531a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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, logger } = {
89+
...contextValue,
90+
...(resolveCustomLogger ? { logger: resolveCustomLogger(contextValue) } : {}),
91+
}
8492
const { operationName, query, variables } = ctx.request
8593
const isIntrospection = query && isIntrospectionQuery(query)
8694
if (isIntrospection && ignoreIntrospectionQueries) return

0 commit comments

Comments
 (0)