From 03a5acc73601e47b5a88a30828effc0a56a59ab5 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 19 Jan 2017 11:01:24 -0700 Subject: [PATCH] Modularized reolvers --- routes/api/graph/resolvers.js | 95 -------------------- routes/api/graph/resolvers/action.js | 19 ++++ routes/api/graph/resolvers/action_summary.js | 16 ++++ routes/api/graph/resolvers/asset.js | 20 +++++ routes/api/graph/resolvers/comment.js | 13 +++ routes/api/graph/resolvers/index.js | 17 ++++ routes/api/graph/resolvers/mutation.js | 16 ++++ routes/api/graph/resolvers/query.js | 16 ++++ routes/api/graph/resolvers/user.js | 7 ++ 9 files changed, 124 insertions(+), 95 deletions(-) delete mode 100644 routes/api/graph/resolvers.js create mode 100644 routes/api/graph/resolvers/action.js create mode 100644 routes/api/graph/resolvers/action_summary.js create mode 100644 routes/api/graph/resolvers/asset.js create mode 100644 routes/api/graph/resolvers/comment.js create mode 100644 routes/api/graph/resolvers/index.js create mode 100644 routes/api/graph/resolvers/mutation.js create mode 100644 routes/api/graph/resolvers/query.js create mode 100644 routes/api/graph/resolvers/user.js diff --git a/routes/api/graph/resolvers.js b/routes/api/graph/resolvers.js deleted file mode 100644 index 4c5f553eb..000000000 --- a/routes/api/graph/resolvers.js +++ /dev/null @@ -1,95 +0,0 @@ -module.exports = { - Query: { - assets(_, args, {loaders}) { - return loaders.Assets.getAll.load(); - }, - asset(_, {id}, {loaders}) { - return loaders.Assets.getByID.load(id); - }, - settings(_, args, {loaders}) { - return loaders.Settings.load(); - }, - me(_, args, {user}) { - return user; - } - }, - Mutation: { - createComment(_, {asset_id, parent_id, body}, {mutators}) { - return mutators.Comment.create({asset_id, parent_id, body}); - }, - createAction(_, {action}, {mutators}) { - return mutators.Action.create(action); - }, - deleteAction(_, {id}, {mutators}) { - return mutators.Action.delete({id}); - }, - updateUserSettings(_, {settings}, {mutators}) { - return mutators.User.updateSettings(settings); - } - }, - Asset: { - comments({id}, _, {loaders}) { - return loaders.Comments.getByAssetID.load(id); - }, - settings({settings = null}, _, {loaders}) { - return loaders.Settings.load() - .then((globalSettings) => { - - if (settings) { - settings = Object.assign({}, settings, globalSettings); - } else { - settings = globalSettings; - } - - return settings; - }); - } - }, - Action: { - action_type({action_type}) { - - // TODO: remove once we cast the data model to have uppercase action - // types. - return action_type.toUpperCase(); - }, - item_type({item_type}) { - - // TODO: remove once we cast the data model to have uppercase item - // types. - return item_type.toUpperCase(); - }, - user({user_id}, _, {loaders}) { - return loaders.Users.getByID.load(user_id); - } - }, - ActionSummary: { - action_type({action_type}) { - - // TODO: remove once we cast the data model to have uppercase action - // types. - return action_type.toUpperCase(); - }, - item_type({item_type}) { - - // TODO: remove once we cast the data model to have uppercase item - // types. - return item_type.toUpperCase(); - } - }, - User: { - actions({id}, _, {loaders}) { - return loaders.Actions.getByID.load(id); - } - }, - Comment: { - user({author_id}, _, {loaders}) { - return loaders.Users.getByID.load(author_id); - }, - replies({id}, _, {loaders}) { - return loaders.Comments.getByParentID.load(id); - }, - actions({id}, _, {loaders}) { - return loaders.Actions.getByID.load(id); - } - } -}; diff --git a/routes/api/graph/resolvers/action.js b/routes/api/graph/resolvers/action.js new file mode 100644 index 000000000..6b42b84dd --- /dev/null +++ b/routes/api/graph/resolvers/action.js @@ -0,0 +1,19 @@ +const Action = { + action_type({action_type}) { + + // TODO: remove once we cast the data model to have uppercase action + // types. + return action_type.toUpperCase(); + }, + item_type({item_type}) { + + // TODO: remove once we cast the data model to have uppercase item + // types. + return item_type.toUpperCase(); + }, + user({user_id}, _, {loaders}) { + return loaders.Users.getByID.load(user_id); + } +}; + +module.exports = Action; diff --git a/routes/api/graph/resolvers/action_summary.js b/routes/api/graph/resolvers/action_summary.js new file mode 100644 index 000000000..662078500 --- /dev/null +++ b/routes/api/graph/resolvers/action_summary.js @@ -0,0 +1,16 @@ +const ActionSummary = { + action_type({action_type}) { + + // TODO: remove once we cast the data model to have uppercase action + // types. + return action_type.toUpperCase(); + }, + item_type({item_type}) { + + // TODO: remove once we cast the data model to have uppercase item + // types. + return item_type.toUpperCase(); + } +}; + +module.exports = ActionSummary; diff --git a/routes/api/graph/resolvers/asset.js b/routes/api/graph/resolvers/asset.js new file mode 100644 index 000000000..f6c055f42 --- /dev/null +++ b/routes/api/graph/resolvers/asset.js @@ -0,0 +1,20 @@ +const Asset = { + comments({id}, _, {loaders}) { + return loaders.Comments.getByAssetID.load(id); + }, + settings({settings = null}, _, {loaders}) { + return loaders.Settings.load() + .then((globalSettings) => { + + if (settings) { + settings = Object.assign({}, settings, globalSettings); + } else { + settings = globalSettings; + } + + return settings; + }); + } +}; + +module.exports = Asset; diff --git a/routes/api/graph/resolvers/comment.js b/routes/api/graph/resolvers/comment.js new file mode 100644 index 000000000..2fdf6f0dd --- /dev/null +++ b/routes/api/graph/resolvers/comment.js @@ -0,0 +1,13 @@ +const Comment = { + user({author_id}, _, {loaders}) { + return loaders.Users.getByID.load(author_id); + }, + replies({id}, _, {loaders}) { + return loaders.Comments.getByParentID.load(id); + }, + actions({id}, _, {loaders}) { + return loaders.Actions.getByID.load(id); + } +}; + +module.exports = Comment; diff --git a/routes/api/graph/resolvers/index.js b/routes/api/graph/resolvers/index.js new file mode 100644 index 000000000..d4de137d5 --- /dev/null +++ b/routes/api/graph/resolvers/index.js @@ -0,0 +1,17 @@ +const Action = require('./action'); +const ActionSummary = require('./action_summary'); +const Asset = require('./asset'); +const Comment = require('./comment'); +const Mutation = require('./mutation'); +const Query = require('./Query'); +const User = require('./user'); + +module.exports = { + Action, + ActionSummary, + Asset, + Comment, + Mutation, + Query, + User +}; diff --git a/routes/api/graph/resolvers/mutation.js b/routes/api/graph/resolvers/mutation.js new file mode 100644 index 000000000..ef95d0334 --- /dev/null +++ b/routes/api/graph/resolvers/mutation.js @@ -0,0 +1,16 @@ +const Mutation = { + createComment(_, {asset_id, parent_id, body}, {mutators}) { + return mutators.Comment.create({asset_id, parent_id, body}); + }, + createAction(_, {action}, {mutators}) { + return mutators.Action.create(action); + }, + deleteAction(_, {id}, {mutators}) { + return mutators.Action.delete({id}); + }, + updateUserSettings(_, {settings}, {mutators}) { + return mutators.User.updateSettings(settings); + } +}; + +module.exports = Mutation; diff --git a/routes/api/graph/resolvers/query.js b/routes/api/graph/resolvers/query.js new file mode 100644 index 000000000..89cbc18c9 --- /dev/null +++ b/routes/api/graph/resolvers/query.js @@ -0,0 +1,16 @@ +const Query = { + assets(_, args, {loaders}) { + return loaders.Assets.getAll.load(); + }, + asset(_, {id}, {loaders}) { + return loaders.Assets.getByID.load(id); + }, + settings(_, args, {loaders}) { + return loaders.Settings.load(); + }, + me(_, args, {user}) { + return user; + } +}; + +module.exports = Query; diff --git a/routes/api/graph/resolvers/user.js b/routes/api/graph/resolvers/user.js new file mode 100644 index 000000000..98d25f524 --- /dev/null +++ b/routes/api/graph/resolvers/user.js @@ -0,0 +1,7 @@ +const User = { + actions({id}, _, {loaders}) { + return loaders.Actions.getByID.load(id); + } +}; + +module.exports = User;