From 361cd9a691dab4c41e4bb5e4001309275f1c7cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lytek?= Date: Wed, 11 Dec 2019 20:55:56 +0100 Subject: [PATCH] Rename util to isPromiseLike --- src/resolvers/create.ts | 4 ++-- src/resolvers/helpers.ts | 4 ++-- src/utils/index.ts | 1 - src/utils/isPromise.ts | 3 --- src/utils/isPromiseLike.ts | 5 +++++ 5 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 src/utils/isPromise.ts create mode 100644 src/utils/isPromiseLike.ts 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..26a971b29 --- /dev/null +++ b/src/utils/isPromiseLike.ts @@ -0,0 +1,5 @@ +export default function isPromiseLike( + value: PromiseLike | TValue, +): value is PromiseLike { + return Boolean(value && "then" in value && typeof value.then === "function"); +}