@@ -15,7 +15,7 @@ import type {
1515 GraphQLFormattedError ,
1616} from 'graphql' ;
1717import accepts from 'accepts' ;
18- import httpError , { HttpError } from 'http-errors' ;
18+ import httpError from 'http-errors' ;
1919import {
2020 Source ,
2121 parse ,
@@ -31,7 +31,9 @@ import type { GraphiQLOptions, GraphiQLData } from './renderGraphiQL';
3131import { parseBody } from './parseBody' ;
3232import { renderGraphiQL } from './renderGraphiQL' ;
3333
34- type Request = IncomingMessage ;
34+ // `url` is always defined for IncomingMessage coming from http.Server
35+ type Request = IncomingMessage & { url : string } ;
36+
3537type Response = ServerResponse & { json ?: ( data : unknown ) => void } ;
3638type MaybePromise < T > = Promise < T > | T ;
3739
@@ -361,11 +363,10 @@ export function graphqlHTTP(options: Options): Middleware {
361363 // If an error was caught, report the httpError status, or 500.
362364 response . statusCode = error . status ?? 500 ;
363365
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 ) ) ;
369370 }
370371 }
371372
@@ -465,9 +466,7 @@ export interface GraphQLParams {
465466export async function getGraphQLParams (
466467 request : Request ,
467468) : 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 ] ) ;
471470 const bodyData = await parseBody ( request ) ;
472471
473472 // GraphQL Query string.
0 commit comments