From 30927dee22d36dc0778ac525459c4b4847a70dc0 Mon Sep 17 00:00:00 2001 From: "Arian Allenson M. Valdez" Date: Mon, 2 May 2016 23:32:51 +0800 Subject: [PATCH 1/4] Use functions for custom mutaitons and queries --- src/schema/schema.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/schema/schema.js b/src/schema/schema.js index 461571a..8c5e977 100644 --- a/src/schema/schema.js +++ b/src/schema/schema.js @@ -220,8 +220,12 @@ function getMutationField(graffitiModel, type, viewer, hooks = {}, allowMongoIDM */ function getFields(graffitiModels, { hooks = {}, mutation = true, allowMongoIDMutation = false, - customQueries = {}, customMutations = {} + customQueries = false, customMutations = false } = {}) { + + if (customQueries === false) customQueries = () => {} + if (customMutations === false) customMutations = () => {} + const types = type.getTypes(graffitiModels); const {viewer, singular} = hooks; @@ -258,8 +262,8 @@ function getFields(graffitiModels, { } }; }, { - queries: customQueries, - mutations: customMutations + queries: customQueries(types), + mutations: customMutations(types) }); const RootQuery = new GraphQLObjectType({ From c87c1b94a16d34ad0e7d32336b1e017559cd2f0d Mon Sep 17 00:00:00 2001 From: "Arian Allenson M. Valdez" Date: Tue, 3 May 2016 11:08:53 +0800 Subject: [PATCH 2/4] Expose processId --- src/index.js | 7 +++++-- src/query/query.js | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 9de26b6..16c540e 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import {graphql} from 'graphql'; import {getTypes} from './type'; import {getSchema} from './schema'; import {getModels} from './model'; +import {processId} from './query'; function _getTypes(mongooseModels) { const graffitiModels = getModels(mongooseModels); @@ -11,11 +12,13 @@ function _getTypes(mongooseModels) { export default { graphql, getSchema, - getTypes: _getTypes + getTypes: _getTypes, + processId }; export { graphql, getSchema, - _getTypes as getTypes + _getTypes as getTypes, + processId }; diff --git a/src/query/query.js b/src/query/query.js index 7cf8c48..534b275 100644 --- a/src/query/query.js +++ b/src/query/query.js @@ -325,7 +325,8 @@ export default { getListResolver, getAddOneMutateHandler, getUpdateOneMutateHandler, - getDeleteOneMutateHandler + getDeleteOneMutateHandler, + processId }; export { From cc85da886af30f403cbeee6045062ee1b3c33fa4 Mon Sep 17 00:00:00 2001 From: "Arian Allenson M. Valdez" Date: Tue, 3 May 2016 11:09:28 +0800 Subject: [PATCH 3/4] Check if customQueries/Mutations are functions --- src/schema/schema.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/schema/schema.js b/src/schema/schema.js index 8c5e977..595cef7 100644 --- a/src/schema/schema.js +++ b/src/schema/schema.js @@ -1,4 +1,4 @@ -import {reduce, isArray} from 'lodash'; +import {reduce, isArray, isFunction} from 'lodash'; import { GraphQLList, GraphQLNonNull, @@ -220,12 +220,9 @@ function getMutationField(graffitiModel, type, viewer, hooks = {}, allowMongoIDM */ function getFields(graffitiModels, { hooks = {}, mutation = true, allowMongoIDMutation = false, - customQueries = false, customMutations = false + customQueries = {}, customMutations = {} } = {}) { - if (customQueries === false) customQueries = () => {} - if (customMutations === false) customMutations = () => {} - const types = type.getTypes(graffitiModels); const {viewer, singular} = hooks; @@ -262,8 +259,8 @@ function getFields(graffitiModels, { } }; }, { - queries: customQueries(types), - mutations: customMutations(types) + queries: isFunction(customQueries) ? customQueries(types) : customQueries, + mutations: isFunction(customMutations) ? customMutations(types) : customMutations }); const RootQuery = new GraphQLObjectType({ From cc03fa39a0af1e0ce74b5b52a090e3553a2a3c1f Mon Sep 17 00:00:00 2001 From: "Arian Allenson M. Valdez" Date: Tue, 3 May 2016 11:16:28 +0800 Subject: [PATCH 4/4] (fix) Expose processId --- src/query/query.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/query/query.js b/src/query/query.js index 534b275..656616e 100644 --- a/src/query/query.js +++ b/src/query/query.js @@ -338,5 +338,6 @@ export { getUpdateOneMutateHandler, getDeleteOneMutateHandler, getListResolver, - connectionFromModel + connectionFromModel, + processId };