Skip to content

Commit 9049f31

Browse files
authored
fix(client): graphql module is not required for runtime (#102)
1 parent c87b47e commit 9049f31

File tree

2 files changed

+33
-44
lines changed

2 files changed

+33
-44
lines changed

src/handler.ts

+33-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ import {
1919
GraphQLError,
2020
} from 'graphql';
2121
import { RequestParams } from './common';
22-
import {
23-
areGraphQLErrors,
24-
isAsyncIterable,
25-
isExecutionResult,
26-
isGraphQLError,
27-
isObject,
28-
jsonErrorReplacer,
29-
} from './utils';
22+
import { isAsyncIterable, isExecutionResult, isObject } from './utils';
3023

3124
/**
3225
* The incoming request headers the implementing server should provide.
@@ -854,3 +847,35 @@ function getHeader(
854847
}
855848
return Object(req.headers)[key];
856849
}
850+
851+
function areGraphQLErrors(obj: unknown): obj is readonly GraphQLError[] {
852+
return (
853+
Array.isArray(obj) &&
854+
obj.length > 0 &&
855+
// if one item in the array is a GraphQLError, we're good
856+
obj.some(isGraphQLError)
857+
);
858+
}
859+
860+
function isGraphQLError(obj: unknown): obj is GraphQLError {
861+
return obj instanceof GraphQLError;
862+
}
863+
864+
function jsonErrorReplacer(
865+
_key: string,
866+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
867+
val: any,
868+
) {
869+
if (
870+
val instanceof Error &&
871+
// GraphQL errors implement their own stringer
872+
!isGraphQLError(val)
873+
) {
874+
return {
875+
// name: val.name, name is included in message
876+
message: val.message,
877+
// stack: val.stack, can leak sensitive details
878+
};
879+
}
880+
return val;
881+
}

src/utils.ts

-36
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import type { ExecutionResult } from 'graphql';
8-
import { GraphQLError } from 'graphql';
98

109
/** @private */
1110
export function extendedTypeof(
@@ -39,21 +38,6 @@ export function isObject(val: unknown): val is Record<
3938
return typeof val === 'object' && val !== null;
4039
}
4140

42-
/** @private */
43-
export function areGraphQLErrors(obj: unknown): obj is readonly GraphQLError[] {
44-
return (
45-
Array.isArray(obj) &&
46-
obj.length > 0 &&
47-
// if one item in the array is a GraphQLError, we're good
48-
obj.some(isGraphQLError)
49-
);
50-
}
51-
52-
/** @private */
53-
export function isGraphQLError(obj: unknown): obj is GraphQLError {
54-
return obj instanceof GraphQLError;
55-
}
56-
5741
/** @private */
5842
export function isExecutionResult(val: unknown): val is ExecutionResult {
5943
return (
@@ -68,23 +52,3 @@ export function isAsyncIterable<T = unknown>(
6852
): val is AsyncIterable<T> {
6953
return typeof Object(val)[Symbol.asyncIterator] === 'function';
7054
}
71-
72-
/** @private */
73-
export function jsonErrorReplacer(
74-
_key: string,
75-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
76-
val: any,
77-
) {
78-
if (
79-
val instanceof Error &&
80-
// GraphQL errors implement their own stringer
81-
!isGraphQLError(val)
82-
) {
83-
return {
84-
// name: val.name, name is included in message
85-
message: val.message,
86-
// stack: val.stack, can leak sensitive details
87-
};
88-
}
89-
return val;
90-
}

0 commit comments

Comments
 (0)