@@ -187,7 +187,7 @@ type Middleware = (request: Request, response: Response) => Promise<void>;
187
187
* configure behavior, and returns an express middleware.
188
188
*/
189
189
export function graphqlHTTP ( options : Options ) : Middleware {
190
- devAssert ( options != null , 'GraphQL middleware requires options.' ) ;
190
+ devAssertIsNonNullable ( options , 'GraphQL middleware requires options.' ) ;
191
191
192
192
return async function graphqlMiddleware (
193
193
request : Request ,
@@ -239,9 +239,8 @@ export function graphqlHTTP(options: Options): Middleware {
239
239
optionsData . formatError ??
240
240
formatErrorFn ;
241
241
242
- // Assert that schema is required.
243
- devAssert (
244
- schema != null ,
242
+ devAssertIsObject (
243
+ schema ,
245
244
'GraphQL middleware options must contain a schema.' ,
246
245
) ;
247
246
@@ -432,8 +431,8 @@ export function graphqlHTTP(options: Options): Middleware {
432
431
: options ,
433
432
) ;
434
433
435
- devAssert (
436
- optionsResult != null && typeof optionsResult === 'object' ,
434
+ devAssertIsObject (
435
+ optionsResult ,
437
436
'GraphQL middleware option function must return an options object or a promise which will be resolved to an options object.' ,
438
437
) ;
439
438
@@ -533,9 +532,17 @@ function sendResponse(response: Response, type: string, data: string): void {
533
532
response . end ( chunk ) ;
534
533
}
535
534
536
- function devAssert ( condition : unknown , message : string ) : asserts condition {
535
+ function devAssertIsObject ( value : unknown , message : string ) : void {
536
+ devAssert ( value != null && typeof value === 'object' , message ) ;
537
+ }
538
+
539
+ function devAssertIsNonNullable ( value : unknown , message : string ) : void {
540
+ devAssert ( value != null , message ) ;
541
+ }
542
+
543
+ function devAssert ( condition : unknown , message : string ) : void {
537
544
const booleanCondition = Boolean ( condition ) ;
538
545
if ( ! booleanCondition ) {
539
- throw new Error ( message ) ;
546
+ throw new TypeError ( message ) ;
540
547
}
541
548
}
0 commit comments