Skip to content

Commit 5a042f3

Browse files
committed
Add request data to invalidRequestWasReceived lifecycle event
1 parent 268687d commit 5a042f3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/server/src/ApolloServer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,10 @@ export class ApolloServer<in out TContext extends BaseContext = BaseContext> {
11011101
await Promise.all(
11021102
this.internals.plugins.map(
11031103
async (plugin) =>
1104-
plugin.invalidRequestWasReceived?.({ error: maybeError }),
1104+
plugin.invalidRequestWasReceived?.({
1105+
request: httpGraphQLRequest,
1106+
error: maybeError,
1107+
}),
11051108
),
11061109
);
11071110
} catch (pluginError) {

packages/server/src/externalTypes/plugins.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323
GraphQLRequestContextWillSendResponse,
2424
GraphQLRequestContextWillSendSubsequentPayload,
2525
} from './requestPipeline.js';
26+
import type { HTTPGraphQLRequest } from './index.js';
2627

2728
export interface GraphQLServerContext {
2829
readonly logger: Logger;
@@ -76,7 +77,13 @@ export interface ApolloServerPlugin<
7677
* incorrect headers, invalid JSON body, or invalid search params for GET),
7778
* but does not include malformed GraphQL.
7879
*/
79-
invalidRequestWasReceived?({ error }: { error: Error }): Promise<void>;
80+
invalidRequestWasReceived?({
81+
request,
82+
error,
83+
}: {
84+
request: HTTPGraphQLRequest;
85+
error: Error;
86+
}): Promise<void>;
8087
// Called on startup fail. This can occur if the schema fails to load or if a
8188
// `serverWillStart` or `renderLandingPage` hook throws.
8289
startupDidFail?({ error }: { error: Error }): Promise<void>;

0 commit comments

Comments
 (0)