Skip to content

Commit

Permalink
Support context creation failure logging (#126)
Browse files Browse the repository at this point in the history
* add `contextCreationDidFail` hook and `contextCreationFailureLogger` logger into logging plugin options
* update all packages
  • Loading branch information
cuzzlor authored Aug 11, 2023
1 parent 50f07df commit 959a575
Show file tree
Hide file tree
Showing 4 changed files with 1,389 additions and 478 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ A set of MakerX plugins for Apollo Server

`loggingPlugin` logs GraphQL operations in a [standard way](https://github.com/MakerXStudio/graphql-core/blob/main/src/logging.ts), using the [`logger`](https://github.com/MakerXStudio/node-common/blob/main/src/logger.ts) from the GraphQL [context](https://github.com/MakerXStudio/graphql-core/blob/main/src/context.ts).

Logging is performed via the `willSendResponse` hook, which will run for operations with errors.
Logging is performed via the `willSendResponse` and `willSendSubsequentPayload` hooks, which will run for operations with errors.

### Options

- `contextCreationFailureLogger`: The plugin does not have access to a logger prior to context creation, so if you wish to log context creation failures, supply a logger here (it will _only_ be called for context creation failure).
- `contextCreationDidFail`: If you wish to custom log or otherwise react to context creation failures, supply a handler for the plugin `contextCreationDidFail` hook (this will be called instead of logging to `contextCreationFailureLogger`).
- `shouldIgnore`: an optional callback that can be used to ignore certain operations, e.g. if you have a healthcheck operation that you prefer not to be logged.

```ts
const plugins: ApolloServerPlugin<GraphQLContext>[] = [createLoggingPlugin({ contextCreationFailureLogger: logger })]
```

Output includes:

Expand Down
Loading

0 comments on commit 959a575

Please sign in to comment.