graphql-http
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -35,4 +35,10 @@ /** | ||
readonly headers: RequestHeaders; | ||
readonly body: string | Record<string, unknown> | null; | ||
/** | ||
* Parsed request body or a parser function. | ||
* | ||
* If the provided function throws, the error message "Unparsable JSON body" will | ||
* be in the erroneous response. | ||
*/ | ||
readonly body: string | Record<string, unknown> | null | (() => string | Record<string, unknown> | null | Promise<string | Record<string, unknown> | null>); | ||
/** | ||
* The raw request itself from the implementing server. | ||
@@ -39,0 +45,0 @@ * |
@@ -145,12 +145,17 @@ "use strict"; | ||
} | ||
let data; | ||
try { | ||
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body; | ||
partParams.operationName = data.operationName; | ||
partParams.query = data.query; | ||
partParams.variables = data.variables; | ||
partParams.extensions = data.extensions; | ||
const body = typeof req.body === 'function' ? await req.body() : req.body; | ||
data = typeof body === 'string' ? JSON.parse(body) : body; | ||
} | ||
catch (_d) { | ||
catch (err) { | ||
throw new Error('Unparsable JSON body'); | ||
} | ||
if (!(0, utils_1.isObject)(data)) { | ||
throw new Error('JSON body must be an object'); | ||
} | ||
partParams.operationName = data.operationName; | ||
partParams.query = data.query; | ||
partParams.variables = data.variables; | ||
partParams.extensions = data.extensions; | ||
break; | ||
@@ -233,3 +238,3 @@ } | ||
} | ||
catch (_e) { | ||
catch (_d) { | ||
return makeResponse(new graphql_1.GraphQLError('Unable to detect operation AST'), acceptedMediaType); | ||
@@ -236,0 +241,0 @@ } |
@@ -8,3 +8,3 @@ /** | ||
/** @private */ | ||
export declare function isObject(val: unknown): val is Record<PropertyKey, unknown>; | ||
export declare function isObject(val: unknown): val is Record<PropertyKey, any>; | ||
/** @private */ | ||
@@ -11,0 +11,0 @@ export declare function areGraphQLErrors(obj: unknown): obj is readonly GraphQLError[]; |
{ | ||
"name": "graphql-http", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -193,7 +193,3 @@ <div align="center"> | ||
headers: req.headers, | ||
body: await new Promise((resolve) => { | ||
let body = ''; | ||
req.on('data', (chunk) => (body += chunk)); | ||
req.on('end', () => resolve(body)); | ||
}), | ||
body: req.body, // fastify reads the body for you | ||
raw: req, | ||
@@ -200,0 +196,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
99711
1845
715