diff --git a/dist/helper.d.ts b/dist/helper.d.ts index d508078..55616ce 100644 --- a/dist/helper.d.ts +++ b/dist/helper.d.ts @@ -4,7 +4,12 @@ export declare const or: (...conditions: any[]) => (resolver: any) => (...query: /** * Constructs a composable resolver with the same arguments as createResolver. * The composable resolver provides the compose method which takes an object of named resolver functions. - * @param resFn resolver function - * @param errFn error handler + * The resolvers object can contain, constructed resolver functions or { resolve: fn, error: fn } params + * to construct a new resolver. Compose returns an object of resolvers who inherit from the baseResolver + * on which compose was called. + * + * @param resFn: resolver function + * @param errFn: error handler + * @returns resolverFn: { createResolver(resFn, errFn), compose({ resolvers }): { composed resolvers } ...} */ export declare const composable: (resFn: any, errFn: any) => (root: any, args?: {}, context?: {}, info?: {}) => Promise; diff --git a/dist/helper.js b/dist/helper.js index 8bae3d4..e44ea8b 100644 --- a/dist/helper.js +++ b/dist/helper.js @@ -31,8 +31,13 @@ exports.or = (...conditions) => resolver => (...query) => { /** * Constructs a composable resolver with the same arguments as createResolver. * The composable resolver provides the compose method which takes an object of named resolver functions. - * @param resFn resolver function - * @param errFn error handler + * The resolvers object can contain, constructed resolver functions or { resolve: fn, error: fn } params + * to construct a new resolver. Compose returns an object of resolvers who inherit from the baseResolver + * on which compose was called. + * + * @param resFn: resolver function + * @param errFn: error handler + * @returns resolverFn: { createResolver(resFn, errFn), compose({ resolvers }): { composed resolvers } ...} */ exports.composable = (resFn, errFn) => { const baseResolver = resolver_1.createResolver(resFn, errFn); @@ -40,7 +45,6 @@ exports.composable = (resFn, errFn) => { const composed = {}; Object.keys(resolvers).forEach(key => { const resolver = resolvers[key]; - // composed[key] = baseResolver['createResolver'](resolver); composed[key] = (resolver.resolve || resolver.error) // supports syntax: compose( { myResolver: { resolve: resFn, error: errFn } } ) ? baseResolver['createResolver'](resolver.resolve, resolver.error) diff --git a/dist/helper.js.map b/dist/helper.js.map index 3aa9f35..4bdd205 100644 --- a/dist/helper.js.map +++ b/dist/helper.js.map @@ -1 +1 @@ -{"version":3,"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AAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACnC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;YAChC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC;gBAClD,+EAA+E;gBAC/E,CAAC,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC;gBAClE,sDAAsD;gBACtD,CAAC,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAA;IAED,OAAO,YAAY,CAAC;AACtB,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 8be43e8..1034f5d 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,5 +1,5 @@ import { usePromise } from './promise'; -import { combineResolvers } from './helper'; +import { combineResolvers, and, or } from './helper'; import { createExpressContext } from './context'; import { createResolver } from './resolver'; -export { usePromise, combineResolvers, createExpressContext, createResolver }; +export { usePromise, combineResolvers, createExpressContext, createResolver, and, or }; diff --git a/dist/index.js b/dist/index.js index c1bd5b2..b8915cc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4,6 +4,8 @@ const promise_1 = require("./promise"); exports.usePromise = promise_1.usePromise; const helper_1 = require("./helper"); exports.combineResolvers = helper_1.combineResolvers; +exports.and = helper_1.and; +exports.or = helper_1.or; const context_1 = require("./context"); exports.createExpressContext = context_1.createExpressContext; const resolver_1 = require("./resolver"); diff --git a/dist/index.js.map b/dist/index.js.map index 24bc5a2..3c385fd 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AAMrC,qBANO,oBAAU,CAMP;AALZ,qCAA4C;AAM1C,2BANO,yBAAgB,CAMP;AALlB,uCAAiD;AAM/C,+BANO,8BAAoB,CAMP;AALtB,yCAA4C;AAM1C,yBANO,yBAAc,CAMP"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AAMrC,qBANO,oBAAU,CAMP;AALZ,qCAAqD;AAMnD,2BANO,yBAAgB,CAMP;AAGhB,cATyB,YAAG,CASzB;AACH,aAV8B,WAAE,CAU9B;AATJ,uCAAiD;AAM/C,+BANO,8BAAoB,CAMP;AALtB,yCAA4C;AAM1C,yBANO,yBAAc,CAMP"} \ No newline at end of file diff --git a/src/helper.ts b/src/helper.ts index acddecb..ecf3ea0 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -33,8 +33,13 @@ export const or = (...conditions) => resolver => (...query) => { /** * Constructs a composable resolver with the same arguments as createResolver. * The composable resolver provides the compose method which takes an object of named resolver functions. - * @param resFn resolver function - * @param errFn error handler + * The resolvers object can contain, constructed resolver functions or { resolve: fn, error: fn } params + * to construct a new resolver. Compose returns an object of resolvers who inherit from the baseResolver + * on which compose was called. + * + * @param resFn: resolver function + * @param errFn: error handler + * @returns resolverFn: { createResolver(resFn, errFn), compose({ resolvers }): { composed resolvers } ...} */ export const composable = (resFn, errFn) => { const baseResolver = createResolver(resFn, errFn); @@ -43,7 +48,6 @@ export const composable = (resFn, errFn) => { const composed = {}; Object.keys(resolvers).forEach(key => { const resolver = resolvers[key]; - // composed[key] = baseResolver['createResolver'](resolver); composed[key] = (resolver.resolve || resolver.error) // supports syntax: compose( { myResolver: { resolve: resFn, error: errFn } } ) ? baseResolver['createResolver'](resolver.resolve, resolver.error)