diff --git a/dist/context.d.ts b/dist/context.d.ts deleted file mode 100644 index 1ff7390..0000000 --- a/dist/context.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface ContextData { - models: Object; - user: Object; -} -export declare const createExpressContext: (data: any, res: any) => Context; -export declare class Context { - models: Object; - user: Object; - constructor(data: ContextData); - dispose(): void; -} diff --git a/dist/context.js b/dist/context.js deleted file mode 100644 index 88b36eb..0000000 --- a/dist/context.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const assert = require("assert"); -; -exports.createExpressContext = (data, res) => { - data = data || {}; - data.user = data.user || null; - data.models = data.models || {}; - const context = new Context(data); - if (res) { - assert(typeof res.once === 'function', 'createExpressContext takes response as second parameter that implements "res.once"'); - // Bind the response finish event to the context disposal method - res.once('finish', () => context && context.dispose ? context.dispose() : null); - } - return context; -}; -class Context { - constructor(data) { - Object.keys(data).forEach(key => { - this[key] = data[key]; - }); - } - dispose() { - const models = this.models; - const user = this.user; - this.models = null; - this.user = null; - // Call dispose on every attached model that contains a dispose method - Object.keys(models).forEach((key) => models[key].dispose ? models[key].dispose() : null); - } -} -exports.Context = Context; -//# sourceMappingURL=context.js.map \ No newline at end of file diff --git a/dist/context.js.map b/dist/context.js.map deleted file mode 100644 index a0aa1eb..0000000 --- a/dist/context.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;AAAA,iCAAiC;AAIhC,CAAC;AACW,QAAA,oBAAoB,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IAChD,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;IAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAChC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,GAAG,EAAE;QACP,MAAM,CAAC,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,EAAE,oFAAoF,CAAC,CAAC;QAC7H,gEAAgE;QAChE,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;KACjF;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;IAGE,YAAa,IAAiB;QAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO;QACL,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,sEAAsE;QACtE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC3F,CAAC;CACF;AAhBD,0BAgBC"} \ No newline at end of file diff --git a/dist/helper.d.ts b/dist/helper.d.ts deleted file mode 100644 index 606f240..0000000 --- a/dist/helper.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare const combineResolvers: (resolvers?: any[]) => any; -export declare const and: (...conditions: any[]) => (resolver: any) => any; -export declare const or: (...conditions: any[]) => (resolver: any) => (...query: any[]) => Promise<{}>; diff --git a/dist/helper.js b/dist/helper.js deleted file mode 100644 index c8c136e..0000000 --- a/dist/helper.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const merge = require("deepmerge"); -// Helper function to combine multiple resolver definition hashes into a single hash for consumption by Apollostack's graphql-server -exports.combineResolvers = (resolvers = []) => resolvers - .reduce((combined, resolver) => merge(combined, resolver)); -// Accepts multiple authentication resolvers and returns a function which will be called -// if all of the authentication resolvers succeed, or throw an error if one of them fails -exports.and = (...conditions) => resolver => { - return conditions.reduceRight((p, c) => { - return c.createResolver(p); - }, resolver); -}; -// Accepts multiple authentication resolvers and returns a function which will be called -// if any of the authentication resolvers succeed, or throw an error if all of them fail -exports.or = (...conditions) => resolver => (...query) => { - return new Promise((resolve, reject) => { - let limit = conditions.length - 1; - const attempt = (i) => conditions[i].createResolver(resolver)(...query) - .then(res => resolve(res)) - .catch(err => { - if (i === limit) - reject(err); - else - attempt(i + 1); - }); - attempt(0); - }); -}; -//# sourceMappingURL=helper.js.map \ No newline at end of file diff --git a/dist/helper.js.map b/dist/helper.js.map deleted file mode 100644 index 6602270..0000000 --- a/dist/helper.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AAEnC,oIAAoI;AACvH,QAAA,gBAAgB,GAAG,CAAC,SAAS,GAAG,EAAE,EAAE,EAAE,CAAC,SAAS;KAC1D,MAAM,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE7D,wFAAwF;AACxF,yFAAyF;AAC5E,QAAA,GAAG,GAAG,CAAC,GAAG,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE;IAC/C,OAAO,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACrC,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC,EAAE,QAAQ,CAAC,CAAA;AACd,CAAC,CAAA;AAED,wFAAwF;AACxF,wFAAwF;AAC3E,QAAA,EAAE,GAAG,CAAC,GAAG,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,EAAE,EAAE;IAC5D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,KAAK,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;QAClC,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,EAAE,CACpB,UAAU,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,GAAG,KAAK,CAAC;aAC7C,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;aACzB,KAAK,CAAC,GAAG,CAAC,EAAE;YACX,IAAG,CAAC,KAAK,KAAK;gBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;;gBACvB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;QACP,OAAO,CAAC,CAAC,CAAC,CAAC;IACb,CAAC,CAAC,CAAC;AACL,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8be43e8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { usePromise } from './promise'; -import { combineResolvers } from './helper'; -import { createExpressContext } from './context'; -import { createResolver } from './resolver'; -export { usePromise, combineResolvers, createExpressContext, createResolver }; diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c1bd5b2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const promise_1 = require("./promise"); -exports.usePromise = promise_1.usePromise; -const helper_1 = require("./helper"); -exports.combineResolvers = helper_1.combineResolvers; -const context_1 = require("./context"); -exports.createExpressContext = context_1.createExpressContext; -const resolver_1 = require("./resolver"); -exports.createResolver = resolver_1.createResolver; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 24bc5a2..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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 diff --git a/dist/promise.d.ts b/dist/promise.d.ts deleted file mode 100644 index c69594c..0000000 --- a/dist/promise.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export declare const usePromise: (pLib: any) => void; -export declare const getPromise: () => PromiseConstructor; diff --git a/dist/promise.js b/dist/promise.js deleted file mode 100644 index a8ffab7..0000000 --- a/dist/promise.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const assert = require("assert"); -// Expose the Promise constructor so that it can be overwritten by a different lib like Bluebird -let p = Promise; -// Allow overload with compliant promise lib -exports.usePromise = pLib => { - assert(pLib && pLib.prototype, 'apollo-errors#usePromise expects a valid Promise library'); - assert(!!pLib.resolve, 'apollo-errors#usePromise expects a Promise library that implements static method "Promise.resolve"'); - assert(!!pLib.reject, 'apollo-errors#usePromise expects a Promise library that implements static method "Promise.reject"'); - assert(!!pLib.all, 'apollo-errors#usePromise expects a Promise library that implements static method "Promise.all"'); - assert(!!pLib.prototype.then, 'apollo-errors#usePromise expects a Promise library that implements method "promise.then" on the constructor prototype'); - assert(!!pLib.prototype.catch, 'apollo-errors#usePromise expects a Promise library that implements method "promise.catch" on the constructor prototype'); - p = pLib; -}; -// Return the currently selected promise lib -exports.getPromise = () => p; -//# sourceMappingURL=promise.js.map \ No newline at end of file diff --git a/dist/promise.js.map b/dist/promise.js.map deleted file mode 100644 index 164c5ba..0000000 --- a/dist/promise.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"promise.js","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":";;AAAA,iCAAiC;AAEjC,gGAAgG;AAChG,IAAI,CAAC,GAAG,OAAO,CAAC;AAEhB,4CAA4C;AAC/B,QAAA,UAAU,GAAG,IAAI,CAAC,EAAE;IAC/B,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,0DAA0D,CAAC,CAAC;IAC3F,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,oGAAoG,CAAC,CAAC;IAC7H,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,mGAAmG,CAAC,CAAC;IAC3H,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,gGAAgG,CAAC,CAAC;IACrH,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,uHAAuH,CAAC,CAAC;IACvJ,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,wHAAwH,CAAC,CAAC;IACzJ,CAAC,GAAG,IAAI,CAAC;AACX,CAAC,CAAC;AAEF,4CAA4C;AAC/B,QAAA,UAAU,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/resolver.d.ts b/dist/resolver.d.ts deleted file mode 100644 index 0f966db..0000000 --- a/dist/resolver.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const createResolver: (resFn: any, errFn: any) => (root: any, args?: {}, context?: {}, info?: {}) => Promise; diff --git a/dist/resolver.js b/dist/resolver.js deleted file mode 100644 index d505d4d..0000000 --- a/dist/resolver.js +++ /dev/null @@ -1,60 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const promise_1 = require("./promise"); -const util_1 = require("./util"); -exports.createResolver = (resFn, errFn) => { - const Promise = promise_1.getPromise(); - const baseResolver = (root, args = {}, context = {}, info = {}) => { - // Return resolving promise with `null` if the resolver function param is not a function - if (!util_1.isFunction(resFn)) - return Promise.resolve(null); - return util_1.Promisify(resFn)(root, args, context, info).catch(e => { - // On error, check if there is an error handler. If not, throw the original error - if (!util_1.isFunction(errFn)) - throw e; - // Call the error handler. - return util_1.Promisify(errFn)(root, args, context, e).then(parsedError => { - // If it resolves, throw the resolving value or the original error. - throw parsedError || e; - }, parsedError => { - // If it rejects, throw the rejecting value or the original error - throw parsedError || e; - }); - }); - }; - baseResolver['createResolver'] = (cResFn, cErrFn) => { - const Promise = promise_1.getPromise(); - const childResFn = (root, args, context, info = {}) => { - // Start with either the parent resolver function or a no-op (returns null) - const entry = util_1.isFunction(resFn) ? util_1.Promisify(resFn)(root, args, context, info) : Promise.resolve(null); - return entry.then(r => { - // If the parent returns a value, continue - if (util_1.isNotNullOrUndefined(r)) - return r; - // Call the child resolver function or a no-op (returns null) - return util_1.isFunction(cResFn) ? util_1.Promisify(cResFn)(root, args, context) : Promise.resolve(null); - }); - }; - const childErrFn = (root, args, context, err) => { - // Start with either the child error handler or a no-op (returns null) - const entry = util_1.isFunction(cErrFn) ? util_1.Promisify(cErrFn)(root, args, context, err) : Promise.resolve(null); - return entry.then(r => { - // If the child returns a value, throw it - if (util_1.isNotNullOrUndefined(r)) - throw r; - // Call the parent error handler or a no-op (returns null) - return util_1.isFunction(errFn) ? util_1.Promisify(errFn)(root, args, context, err).then(e => { - // If it resolves, throw the resolving value or the original error - throw e || err; - }, e => { - // If it rejects, throw the rejecting value or the original error - throw e || err; - }) : Promise.resolve(null); - }); - }; - // Create the child resolver and return it - return exports.createResolver(childResFn, childErrFn); - }; - return baseResolver; -}; -//# sourceMappingURL=resolver.js.map \ No newline at end of file diff --git a/dist/resolver.js.map b/dist/resolver.js.map deleted file mode 100644 index ef15a6c..0000000 --- a/dist/resolver.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"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"} \ No newline at end of file diff --git a/dist/util.d.ts b/dist/util.d.ts deleted file mode 100644 index 1d83213..0000000 --- a/dist/util.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare const isFunction: (fn: any) => boolean; -export declare const Promisify: (fn: any) => (...args: any[]) => Promise<{}>; -export declare const isNotNullOrUndefined: (val: any) => boolean; diff --git a/dist/util.js b/dist/util.js deleted file mode 100644 index 30313ca..0000000 --- a/dist/util.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const promise_1 = require("./promise"); -exports.isFunction = fn => typeof fn === 'function'; -exports.Promisify = fn => { - const Promise = promise_1.getPromise(); - return (...args) => new Promise((resolve, reject) => { - try { - return Promise.resolve(fn(...args)).then(r => resolve(r), e => reject(e)); - } - catch (e) { - return reject(e); - } - }); -}; -exports.isNotNullOrUndefined = val => val !== null && val !== undefined; -//# sourceMappingURL=util.js.map \ No newline at end of file diff --git a/dist/util.js.map b/dist/util.js.map deleted file mode 100644 index d1a4263..0000000 --- a/dist/util.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AAE1B,QAAA,UAAU,GAAG,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,UAAU,CAAC;AAE5C,QAAA,SAAS,GAAG,EAAE,CAAC,EAAE;IAC5B,MAAM,OAAO,GAAG,oBAAU,EAAE,CAAC;IAC7B,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAClD,IAAI;YACF,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3E;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;SAClB;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEW,QAAA,oBAAoB,GAAG,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,CAAC"} \ No newline at end of file diff --git a/src/resolver.ts b/src/resolver.ts index c9c2207..a734582 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -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 { + (root, args, context, info): Promise | ResulType | void +} + +export interface ErrorFunction { + (root, args, context, err): ErrorType | void +} + +export interface CreateResolverFunction { + (resFn: ResultFunction, errFn?: ErrorFunction): Resolver +} + +export interface Resolver { + (root, args: {}, context: {}, info: {}): Promise + createResolver?: CreateResolverFunction +} + +export const createResolver: CreateResolverFunction = (resFn: ResultFunction, errFn: ErrorFunction) => { const Promise = getPromise(); - const baseResolver = (root, args = {}, context = {}, info = {}) => { + const baseResolver: Resolver = (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 => { @@ -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 = {}) => { diff --git a/src/util.ts b/src/util.ts index 8fad04c..55a28d2 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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();