diff --git a/src/resolvers/create.ts b/src/resolvers/create.ts index fc771012a..c74871891 100644 --- a/src/resolvers/create.ts +++ b/src/resolvers/create.ts @@ -9,7 +9,7 @@ import { getParams, applyMiddlewares, applyAuthChecker } from "./helpers"; import { convertToType } from "../helpers/types"; import { BuildContext } from "../schema/build-context"; import { ResolverData } from "../interfaces"; -import { isPromise } from "../utils"; +import isPromiseLike from "../utils/isPromiseLike"; export function createHandlerResolver( resolverMetadata: BaseResolverMetadata, @@ -35,7 +35,7 @@ export function createHandlerResolver( globalValidate, pubSub, ); - if (isPromise(params)) { + if (isPromiseLike(params)) { return params.then(resolvedParams => targetInstance[resolverMetadata.methodName].apply(targetInstance, resolvedParams), ); diff --git a/src/resolvers/helpers.ts b/src/resolvers/helpers.ts index 7bdf5e767..b3893e0ba 100644 --- a/src/resolvers/helpers.ts +++ b/src/resolvers/helpers.ts @@ -9,7 +9,7 @@ import { Middleware, MiddlewareFn, MiddlewareClass } from "../interfaces/Middlew import { IOCContainer } from "../utils/container"; import { AuthMiddleware } from "../helpers/auth-middleware"; import { convertArgsToInstance, convertArgToInstance } from "./convert-args"; -import { isPromise } from "../utils/isPromise"; +import isPromiseLike from "../utils/isPromiseLike"; export function getParams( params: ParamMetadata[], @@ -57,7 +57,7 @@ export function getParams( return paramInfo.resolver(resolverData); } }); - if (paramValues.some(isPromise)) { + if (paramValues.some(isPromiseLike)) { return Promise.all(paramValues); } else { return paramValues; diff --git a/src/utils/index.ts b/src/utils/index.ts index 5b89e41fc..ae0474d9b 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -7,4 +7,3 @@ export { defaultPrintSchemaOptions, } from "./emitSchemaDefinitionFile"; export { ContainerType, ContainerGetter } from "./container"; -export { isPromise } from "./isPromise"; diff --git a/src/utils/isPromise.ts b/src/utils/isPromise.ts deleted file mode 100644 index a97644669..000000000 --- a/src/utils/isPromise.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isPromise(value: PromiseLike | T): value is PromiseLike { - return Boolean(value && typeof (value as any).then === "function"); -} diff --git a/src/utils/isPromiseLike.ts b/src/utils/isPromiseLike.ts new file mode 100644 index 000000000..1a9743f3b --- /dev/null +++ b/src/utils/isPromiseLike.ts @@ -0,0 +1,5 @@ +export default function isPromiseLike( + value: PromiseLike | TValue, +): value is PromiseLike { + return value != null && typeof (value as PromiseLike).then === "function"; +}