diff --git a/src/handler.ts b/src/handler.ts index 3f0f107d..67b59f28 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -19,14 +19,7 @@ import { GraphQLError, } from 'graphql'; import { RequestParams } from './common'; -import { - areGraphQLErrors, - isAsyncIterable, - isExecutionResult, - isGraphQLError, - isObject, - jsonErrorReplacer, -} from './utils'; +import { isAsyncIterable, isExecutionResult, isObject } from './utils'; /** * The incoming request headers the implementing server should provide. @@ -854,3 +847,35 @@ function getHeader( } return Object(req.headers)[key]; } + +function areGraphQLErrors(obj: unknown): obj is readonly GraphQLError[] { + return ( + Array.isArray(obj) && + obj.length > 0 && + // if one item in the array is a GraphQLError, we're good + obj.some(isGraphQLError) + ); +} + +function isGraphQLError(obj: unknown): obj is GraphQLError { + return obj instanceof GraphQLError; +} + +function jsonErrorReplacer( + _key: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + val: any, +) { + if ( + val instanceof Error && + // GraphQL errors implement their own stringer + !isGraphQLError(val) + ) { + return { + // name: val.name, name is included in message + message: val.message, + // stack: val.stack, can leak sensitive details + }; + } + return val; +} diff --git a/src/utils.ts b/src/utils.ts index 84805800..6e33c345 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,7 +5,6 @@ */ import type { ExecutionResult } from 'graphql'; -import { GraphQLError } from 'graphql'; /** @private */ export function extendedTypeof( @@ -39,21 +38,6 @@ export function isObject(val: unknown): val is Record< return typeof val === 'object' && val !== null; } -/** @private */ -export function areGraphQLErrors(obj: unknown): obj is readonly GraphQLError[] { - return ( - Array.isArray(obj) && - obj.length > 0 && - // if one item in the array is a GraphQLError, we're good - obj.some(isGraphQLError) - ); -} - -/** @private */ -export function isGraphQLError(obj: unknown): obj is GraphQLError { - return obj instanceof GraphQLError; -} - /** @private */ export function isExecutionResult(val: unknown): val is ExecutionResult { return ( @@ -68,23 +52,3 @@ export function isAsyncIterable( ): val is AsyncIterable { return typeof Object(val)[Symbol.asyncIterator] === 'function'; } - -/** @private */ -export function jsonErrorReplacer( - _key: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - val: any, -) { - if ( - val instanceof Error && - // GraphQL errors implement their own stringer - !isGraphQLError(val) - ) { - return { - // name: val.name, name is included in message - message: val.message, - // stack: val.stack, can leak sensitive details - }; - } - return val; -}