Skip to content

Commit a682f85

Browse files
fix: Allow already-parsed body objects (#35)
Fixes a regression introduced in #28. If the body is already parsed and it's a valid POST request, we can just return it. Co-authored-by: Trevor Scheer <[email protected]>
1 parent b26c665 commit a682f85

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

.changeset/itchy-icons-flash.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@as-integrations/azure-functions': patch
3+
---
4+
5+
Fix a regression w.r.t body parsing introduced in https://github.com/apollo-server-integrations/apollo-server-integration-azure-functions/pull/28.
6+
7+
Bodies which are already parsed object should just be returned outright rather than treated as invalid.
8+
9+
This issue manifests for users as an invalid POST request from Apollo Server.

src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,17 @@ function parseBody(
9090
contentType: string | undefined,
9191
): object | null {
9292
const isValidContentType = contentType?.startsWith('application/json');
93-
const isValidPostRequest =
94-
method === 'POST' && typeof body === 'string' && isValidContentType;
93+
const isValidPostRequest = method === 'POST' && isValidContentType;
9594

9695
if (isValidPostRequest) {
97-
return JSON.parse(body);
96+
if (typeof body === 'string') {
97+
return JSON.parse(body);
98+
}
99+
if (typeof body === 'object') {
100+
return body;
101+
}
98102
}
103+
99104
return null;
100105
}
101106

0 commit comments

Comments
 (0)