@@ -15,7 +15,7 @@ import type {
15
15
GraphQLFormattedError ,
16
16
} from 'graphql' ;
17
17
import accepts from 'accepts' ;
18
- import httpError , { HttpError } from 'http-errors' ;
18
+ import httpError from 'http-errors' ;
19
19
import {
20
20
Source ,
21
21
parse ,
@@ -31,7 +31,9 @@ import type { GraphiQLOptions, GraphiQLData } from './renderGraphiQL';
31
31
import { parseBody } from './parseBody' ;
32
32
import { renderGraphiQL } from './renderGraphiQL' ;
33
33
34
- type Request = IncomingMessage ;
34
+ // `url` is always defined for IncomingMessage coming from http.Server
35
+ type Request = IncomingMessage & { url : string } ;
36
+
35
37
type Response = ServerResponse & { json ?: ( data : unknown ) => void } ;
36
38
type MaybePromise < T > = Promise < T > | T ;
37
39
@@ -361,11 +363,10 @@ export function graphqlHTTP(options: Options): Middleware {
361
363
// If an error was caught, report the httpError status, or 500.
362
364
response . statusCode = error . status ?? 500 ;
363
365
364
- if ( error . headers ) {
365
- const err = error as HttpError ;
366
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
367
- for ( const [ key , value ] of Object . entries ( err . headers ! ) ) {
368
- response . setHeader ( key , value ) ;
366
+ const { headers } = error ;
367
+ if ( headers != null ) {
368
+ for ( const [ key , value ] of Object . entries ( headers ) ) {
369
+ response . setHeader ( key , String ( value ) ) ;
369
370
}
370
371
}
371
372
@@ -465,9 +466,7 @@ export interface GraphQLParams {
465
466
export async function getGraphQLParams (
466
467
request : Request ,
467
468
) : Promise < GraphQLParams > {
468
- // `url` is always defined for IncomingMessage coming from http.Server
469
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
470
- const urlData = new URLSearchParams ( request . url ! . split ( '?' ) [ 1 ] ) ;
469
+ const urlData = new URLSearchParams ( request . url . split ( '?' ) [ 1 ] ) ;
471
470
const bodyData = await parseBody ( request ) ;
472
471
473
472
// GraphQL Query string.
0 commit comments