diff --git a/package.json b/package.json index 269ab90..a0151ca 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "peerDependencies": { "@apollo/server": "^4.1.1", - "h3": "^0.8.6 || ^1.0.0" + "h3": "^1.8.0" }, "devDependencies": { "@apollo/server": "^4.9.1", diff --git a/src/index.ts b/src/index.ts index 5191205..10e25f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,8 +13,7 @@ import { HTTPMethod, isMethod, setHeaders, - readRawBody, - getRequestHeader, + readBody, } from 'h3' import type { IncomingHttpHeaders } from 'http' @@ -117,13 +116,7 @@ function normalizeQueryString(url: string | undefined): string { async function normalizeBody(event: H3Event): Promise { const PayloadMethods: HTTPMethod[] = ['PATCH', 'POST', 'PUT', 'DELETE'] if (isMethod(event, PayloadMethods)) { - // We cannot use 'readBody' here because it will hide errors in the json parsing - const body = await readRawBody(event) - if (getRequestHeader(event, 'content-type')?.includes('application/json')) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return body ? JSON.parse(body) : {} - } else { - return body - } + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return await readBody(event) } }