From ab726288717f09333b991e4ecacec15162eae838 Mon Sep 17 00:00:00 2001 From: Tim Huff Date: Thu, 15 Feb 2018 16:15:54 -0600 Subject: [PATCH] Add `extendWithModelMutations` function to builder --- lib/SchemaBuilder.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/SchemaBuilder.js b/lib/SchemaBuilder.js index cd0e8ad..ee0d0bc 100644 --- a/lib/SchemaBuilder.js +++ b/lib/SchemaBuilder.js @@ -89,6 +89,25 @@ class SchemaBuilder { this.mutation = mutations; return this; } + + extendWithModelMutations() { + Object.values(this.models).forEach(model => { + this._typeForModel(model); + model.modelClass.GraphqlTypes = this.typeCache; + }); + let mutations = {}; + Object.values(this.models).forEach(model => { + mutations = Object.assign(mutations, model.modelClass.mutations) + }); + this.extendWithMutations( + new GraphQLObjectType({ + name: 'RootMutationType', + description: 'Domain API actions', + fields: () => mutations + }) + ); + return this; + } setBuilderOptions(options) { this.builderOptions = options;