Skip to content

Commit

Permalink
Add request data to invalidRequestWasReceived lifecycle event
Browse files Browse the repository at this point in the history
  • Loading branch information
Masadow committed Jun 10, 2024
1 parent 268687d commit 5a042f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/server/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,10 @@ export class ApolloServer<in out TContext extends BaseContext = BaseContext> {
await Promise.all(
this.internals.plugins.map(
async (plugin) =>
plugin.invalidRequestWasReceived?.({ error: maybeError }),
plugin.invalidRequestWasReceived?.({
request: httpGraphQLRequest,
error: maybeError,
}),
),
);
} catch (pluginError) {
Expand Down
9 changes: 8 additions & 1 deletion packages/server/src/externalTypes/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
GraphQLRequestContextWillSendResponse,
GraphQLRequestContextWillSendSubsequentPayload,
} from './requestPipeline.js';
import type { HTTPGraphQLRequest } from './index.js';

export interface GraphQLServerContext {
readonly logger: Logger;
Expand Down Expand Up @@ -76,7 +77,13 @@ export interface ApolloServerPlugin<
* incorrect headers, invalid JSON body, or invalid search params for GET),
* but does not include malformed GraphQL.
*/
invalidRequestWasReceived?({ error }: { error: Error }): Promise<void>;
invalidRequestWasReceived?({
request,
error,
}: {
request: HTTPGraphQLRequest;
error: Error;
}): Promise<void>;
// Called on startup fail. This can occur if the schema fails to load or if a
// `serverWillStart` or `renderLandingPage` hook throws.
startupDidFail?({ error }: { error: Error }): Promise<void>;
Expand Down

0 comments on commit 5a042f3

Please sign in to comment.