diff --git a/src/graphql/resolvers.js b/src/graphql/resolvers.js index be6faa7551d44ed0f19fdb5682138d4a77e9096e..dfcc206f3600108603fb48aa2ad16312c8f157b8 100644 --- a/src/graphql/resolvers.js +++ b/src/graphql/resolvers.js @@ -69,6 +69,14 @@ export const resolvers = { 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 @@ -227,15 +235,16 @@ export const resolvers = { Message: { __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: { - authors: (obj, args, context) => { - return knex.select().from('groups').whereIn('uid', obj.authors); - } }, Announcement: { diff --git a/src/graphql/schema.js b/src/graphql/schema.js index 720f983a2a8081d20dda52573eebf202740c4697..39fc0087a5121a640a0dec8c5502383101408d81 100644 --- a/src/graphql/schema.js +++ b/src/graphql/schema.js @@ -12,7 +12,9 @@ const typeDefs = actionDefs.concat(objectDefs); const schema = makeExecutableSchema({ typeDefs, - resolvers + resolvers, + logger: {log: e => console.log(e)}, + inheritResolversFromInterfaces: true }); export default schema; \ No newline at end of file