Skip to content

Commit

Permalink
Rename util to isPromiseLike
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLytek committed Dec 11, 2019
1 parent 155c17c commit 361cd9a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/resolvers/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
);
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ export {
defaultPrintSchemaOptions,
} from "./emitSchemaDefinitionFile";
export { ContainerType, ContainerGetter } from "./container";
export { isPromise } from "./isPromise";
3 changes: 0 additions & 3 deletions src/utils/isPromise.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/utils/isPromiseLike.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function isPromiseLike<TValue>(
value: PromiseLike<TValue> | TValue,
): value is PromiseLike<TValue> {
return Boolean(value && "then" in value && typeof value.then === "function");
}

0 comments on commit 361cd9a

Please sign in to comment.