Skip to content

Commit f500fa7

Browse files
committed
fix(handler): JSON body must be an object
1 parent 268a4bf commit f500fa7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/handler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ export function createHandler<RawRequest = unknown, Context = unknown>(
434434
} catch (err) {
435435
throw new Error('Unparsable JSON body');
436436
}
437+
if (!isObject(data)) {
438+
throw new Error('JSON body must be an object');
439+
}
437440
partParams.operationName = data.operationName;
438441
partParams.query = data.query;
439442
partParams.variables = data.variables;

src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import type { ExecutionResult, GraphQLError } from 'graphql';
88

99
/** @private */
10-
export function isObject(val: unknown): val is Record<PropertyKey, unknown> {
10+
export function isObject(val: unknown): val is Record<
11+
PropertyKey,
12+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13+
any
14+
> {
1115
return typeof val === 'object' && val !== null;
1216
}
1317

0 commit comments

Comments
 (0)