Modularized reolvers

This commit is contained in:
Wyatt Johnson
2017-01-19 11:01:24 -07:00
parent d683b09b1d
commit 03a5acc736
9 changed files with 124 additions and 95 deletions
-95
View File
@@ -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);
}
}
};
+19
View File
@@ -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;
@@ -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;
+20
View File
@@ -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;
+13
View File
@@ -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;
+17
View File
@@ -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
};
+16
View File
@@ -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;
+16
View File
@@ -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;
+7
View File
@@ -0,0 +1,7 @@
const User = {
actions({id}, _, {loaders}) {
return loaders.Actions.getByID.load(id);
}
};
module.exports = User;