From 5f8a400812e0af36b3feff4150dd451fd3c8c1dc Mon Sep 17 00:00:00 2001 From: Charles Fonseca Date: Wed, 6 Nov 2024 12:45:36 -0300 Subject: [PATCH] Add body to context --- src/func-v4.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/func-v4.ts b/src/func-v4.ts index 82fe7f3..81c23d4 100644 --- a/src/func-v4.ts +++ b/src/func-v4.ts @@ -15,7 +15,13 @@ import type { WithRequired } from '@apollo/utils.withrequired'; export interface AzureFunctionsContextFunctionArgument { context: InvocationContext; - req: HttpRequest; + // Omit the body parsing methods from the HttpRequest type, since at this point the body has already been parsed + // if the user try to use the body parsing methods, it will throw an error + req: Omit< + HttpRequest, + 'body' | 'arrayBuffer' | 'blob' | 'formData' | 'json' | 'text' + >; + body: unknown; } export interface AzureFunctionsMiddlewareOptions { @@ -47,7 +53,7 @@ export function startServerAndCreateHandler( const { body, headers, status } = await server.executeHTTPGraphQLRequest({ httpGraphQLRequest: normalizedRequest, - context: () => contextFunction({ context, req }), + context: () => contextFunction({ context, req, body: normalizedRequest.body }), }); if (body.kind === 'chunked') {