Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigredgeek authored Jun 6, 2018
2 parents 5b877aa + f0a1267 commit 6428799
Show file tree
Hide file tree
Showing 20 changed files with 22 additions and 204 deletions.
11 changes: 0 additions & 11 deletions dist/context.d.ts

This file was deleted.

33 changes: 0 additions & 33 deletions dist/context.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/context.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/helper.d.ts

This file was deleted.

30 changes: 0 additions & 30 deletions dist/helper.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/helper.js.map

This file was deleted.

5 changes: 0 additions & 5 deletions dist/index.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions dist/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions dist/promise.d.ts

This file was deleted.

18 changes: 0 additions & 18 deletions dist/promise.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/promise.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/resolver.d.ts

This file was deleted.

60 changes: 0 additions & 60 deletions dist/resolver.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/resolver.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/util.d.ts

This file was deleted.

17 changes: 0 additions & 17 deletions dist/util.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/util.js.map

This file was deleted.

24 changes: 21 additions & 3 deletions src/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import { getPromise } from './promise';
import { isFunction, Promisify, isNotNullOrUndefined } from './util';

const Promise = getPromise();

export const createResolver = (resFn, errFn) => {
export interface ResultFunction<ResulType> {
(root, args, context, info): Promise<ResulType> | ResulType | void
}

export interface ErrorFunction<ErrorType> {
(root, args, context, err): ErrorType | void
}

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

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

export const createResolver: CreateResolverFunction = <R, E>(resFn: ResultFunction<R>, errFn: ErrorFunction<E>) => {
const Promise = getPromise();
const baseResolver = (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 @@ -20,7 +38,7 @@ export const createResolver = (resFn, errFn) => {
});
});
};
baseResolver['createResolver'] = (cResFn, cErrFn) => {
baseResolver.createResolver = (cResFn, cErrFn) => {
const Promise = getPromise();

const childResFn = (root, args, context, info = {}) => {
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPromise } from './promise';

export const isFunction = fn => typeof fn === 'function';
export const isFunction = fn => typeof fn === 'function' || fn instanceof Function;

export const Promisify = fn => {
const Promise = getPromise();
Expand Down

0 comments on commit 6428799

Please sign in to comment.