Skip to content
Snippets Groups Projects
Commit fc938762 authored by Wilson JALLET's avatar Wilson JALLET :money_with_wings:
Browse files

Resolver for message type

Based on checking if a given message instance has a location field
(location exists only on Events)
parent 80687204
No related branches found
No related tags found
No related merge requests found
...@@ -69,6 +69,14 @@ export const resolvers = { ...@@ -69,6 +69,14 @@ export const resolvers = {
return knex.select().from("events"); return knex.select().from("events");
}, },
allMessages: function(obj, args, context) {
const events = knex.select().from("events");
const posts = knex.select().from("posts");
return Promise.all([events, posts]).then(res => {
return _.flatten(res);
});
},
// user queries // user queries
...@@ -227,15 +235,16 @@ export const resolvers = { ...@@ -227,15 +235,16 @@ export const resolvers = {
Message: { Message: {
__resolveType: function(obj) { __resolveType: function(obj) {
return obj.type; if (obj.hasOwnProperty('location')) return "Event";
else return "Post";
},
authors: (obj, args, context) => {
return knex.select().from('groups').whereIn('uid', obj.authors);
} }
}, },
Post: { Post: {
authors: (obj, args, context) => {
return knex.select().from('groups').whereIn('uid', obj.authors);
}
}, },
Announcement: { Announcement: {
......
...@@ -12,7 +12,9 @@ const typeDefs = actionDefs.concat(objectDefs); ...@@ -12,7 +12,9 @@ const typeDefs = actionDefs.concat(objectDefs);
const schema = makeExecutableSchema({ const schema = makeExecutableSchema({
typeDefs, typeDefs,
resolvers resolvers,
logger: {log: e => console.log(e)},
inheritResolversFromInterfaces: true
}); });
export default schema; export default schema;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment