mirror of
https://github.com/wassname/talk.git
synced 2026-08-11 11:27:10 +08:00
Modularized reolvers
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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
|
||||
};
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,7 @@
|
||||
const User = {
|
||||
actions({id}, _, {loaders}) {
|
||||
return loaders.Actions.getByID.load(id);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = User;
|
||||
Reference in New Issue
Block a user