Skip to content

Commit 2187f0d

Browse files
authored
refactor(handler): thorough check for Response type (#127)
1 parent c51cc5d commit 2187f0d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/handler.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,18 @@ export type Response = readonly [body: ResponseBody | null, init: ResponseInit];
118118

119119
/** Checks whether the passed value is the `graphql-http` server agnostic response. */
120120
function isResponse(val: unknown): val is Response {
121-
// TODO: make sure the contents of init match ResponseInit
122-
return (
123-
Array.isArray(val) &&
124-
(typeof val[0] === 'string' || val[0] === null) &&
125-
isObject(val[1])
126-
);
121+
// Make sure the contents of body match string | null
122+
if (!Array.isArray(val)) return false;
123+
if (typeof val[0] !== 'string' || val[0] !== null) return false;
124+
if (!isObject(val[1])) return false;
125+
126+
// Make sure the contents of init match ResponseInit
127+
const init = val[1];
128+
if (typeof init.status !== 'number') return false;
129+
if (typeof init.statusText !== 'string') return false;
130+
if (init.headers && !isObject(init.headers)) return false;
131+
132+
return true;
127133
}
128134

129135
/**

0 commit comments

Comments
 (0)