@@ -3,17 +3,15 @@ import { EventEmitter } from 'events';
33import { Duplex } from 'stream' ;
44import DuplexPair = require( 'native-duplexpair' ) ;
55import { TypedError } from 'typed-error' ;
6- import * as CrossFetch from 'cross-fetch' ;
76import * as WebSocket from 'isomorphic-ws' ;
87import connectWebSocketStream = require( '@httptoolkit/websocket-stream' ) ;
98import { SubscriptionClient } from '@httptoolkit/subscriptions-transport-ws' ;
10- import { MaybePromise , getDeferred } from '@httptoolkit/util' ;
9+ import { ErrorLike , MaybePromise , getDeferred } from '@httptoolkit/util' ;
1110import { print } from 'graphql' ;
1211
1312import { DEFAULT_ADMIN_SERVER_PORT } from "../types" ;
1413
1514import { RequireProps } from '../util/type-utils' ;
16- import { isNode } from '../util/util' ;
1715import { delay , isErrorLike } from '@httptoolkit/util' ;
1816
1917import { introspectionQuery } from './schema-introspection' ;
@@ -22,10 +20,6 @@ import { AdminPlugin, PluginClientResponsesMap, PluginStartParamsMap } from '../
2220import { SchemaIntrospector } from './schema-introspection' ;
2321import { AdminQuery , getSingleSelectedFieldName } from './admin-query' ;
2422
25- const { fetch, Headers } = isNode || typeof globalThis . fetch === 'undefined'
26- ? CrossFetch
27- : globalThis ;
28-
2923export class ConnectionError extends TypedError { }
3024
3125// The Response type requires lib.dom. We include an empty placeholder here to
@@ -135,9 +129,14 @@ async function requestFromAdminServer<T>(serverUrl: string, path: string, option
135129 try {
136130 response = await fetch ( url , options ) ;
137131 } catch ( e ) {
138- if ( isErrorLike ( e ) && e . code === 'ECONNREFUSED' ) {
132+ if ( isErrorLike ( e ) && (
133+ e . code === 'ECONNREFUSED' ||
134+ ( e . cause as ErrorLike ) ?. code === 'ECONNREFUSED' )
135+ ) {
139136 throw new ConnectionError ( `Failed to connect to admin server at ${ serverUrl } ` ) ;
140- } else throw e ;
137+ } else {
138+ throw e ;
139+ }
141140 }
142141
143142 if ( response . status >= 400 ) {
@@ -160,7 +159,7 @@ async function requestFromAdminServer<T>(serverUrl: string, path: string, option
160159 ) ;
161160 }
162161 } else {
163- return response . json ( ) ;
162+ return response . json ( ) as Promise < T > ;
164163 }
165164}
166165
@@ -397,7 +396,7 @@ export class AdminClient<Plugins extends { [key: string]: AdminPlugin<any, any>
397396 body : JSON . stringify ( { query, variables } )
398397 } ) ) ;
399398
400- const { data, errors } : { data ?: T , errors ?: Error [ ] } = await response . json ( ) ;
399+ const { data, errors } = await response . json ( ) as { data ?: T , errors ?: Error [ ] } ;
401400
402401 if ( errors && errors . length ) {
403402 throw new GraphQLError ( response , errors ) ;
@@ -411,7 +410,7 @@ export class AdminClient<Plugins extends { [key: string]: AdminPlugin<any, any>
411410
412411 let graphQLErrors : Error [ ] | undefined = undefined ;
413412 try {
414- graphQLErrors = ( await e . response . json ( ) ) . errors ;
413+ graphQLErrors = ( await e . response . json ( ) as { errors ?: Error [ ] } ) . errors ;
415414 } catch ( e2 ) { }
416415
417416 if ( graphQLErrors ) {
0 commit comments