Skip to content

Commit

Permalink
Merge pull request #36 from doomsower/master
Browse files Browse the repository at this point in the history
Improve typescript defs
  • Loading branch information
thebigredgeek authored Jul 2, 2018
2 parents 7d49d06 + 6e31806 commit edfc00a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { usePromise } from './promise';
import { combineResolvers, and, or } from './helper';
import { createExpressContext } from './context';
import { createResolver } from './resolver';
import { createResolver, Resolver, CreateResolverFunction } from './resolver';

export {
usePromise,
combineResolvers,
createExpressContext,
createResolver,
and,
or
or,
Resolver,
CreateResolverFunction,
};
10 changes: 5 additions & 5 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface ErrorFunction<ErrorType> {
}

export interface CreateResolverFunction {
<R, E>(resFn: ResultFunction<R>, errFn?: ErrorFunction<E>): Resolver<R>
<R, E>(resFn: ResultFunction<R> | null, errFn?: ErrorFunction<E>): Resolver<R>
}

export interface ComposeResolversFunction {
Expand All @@ -21,13 +21,13 @@ export interface ComposeResolversFunction {

export interface Resolver<ResulType> {
(root, args: {}, context: {}, info: {}): Promise<ResulType>
createResolver?: CreateResolverFunction
compose?: ComposeResolversFunction
createResolver: CreateResolverFunction
compose: ComposeResolversFunction
}

export const createResolver: CreateResolverFunction = <R, E>(resFn: ResultFunction<R>, errFn: ErrorFunction<E>) => {
const Promise = getPromise();
const baseResolver: Resolver<R> = (root, args = {}, context = {}, info = {}) => {
const baseResolver: Resolver<R> = ((root, args = {}, context = {}, info = {}) => {
// Return resolving promise with `null` if the resolver function param is not a function
if (!isFunction(resFn)) return Promise.resolve(null);
return Promisify(resFn)(root, args, context, info).catch(e => {
Expand All @@ -42,7 +42,7 @@ export const createResolver: CreateResolverFunction = <R, E>(resFn: ResultFuncti
throw parsedError || e
});
});
};
}) as any;

baseResolver.createResolver = (cResFn, cErrFn) => {
const Promise = getPromise();
Expand Down

0 comments on commit edfc00a

Please sign in to comment.