January 2019
Intermediate to advanced
460 pages
10h 33m
English
We can use the addPost mutation as our basis, and extend it. The result accepts a chatId and uses the first user from our database. Later, the authentication will be the source of the user ID:
addMessage(root, { message }, context) { logger.log({ level: 'info', message: 'Message was created', }); return User.findAll().then((users) => { const usersRow = users[0]; return Message.create({ ...message, }).then((newMessage) => { return Promise.all([ newMessage.setUser(usersRow.id), newMessage.setChat(message.chatId), ]).then(() => { return newMessage; }); }); });},
Read now
Unlock full access