January 2019
Intermediate to advanced
460 pages
10h 33m
English
New users want to chat with their friends. Creating a new chat is essential, of course.
The best way to do this is to accept a list of user IDs that also allows the creation of group chats. Do this as follows:
addChat(root, { chat }, context) { logger.log({ level: 'info', message: 'Message was created', }); return Chat.create().then((newChat) => { return Promise.all([ newChat.setUsers(chat.users), ]).then(() => { return newChat; }); });},
Sequelize added the setUsers function to the chat model instance. It was added because of the associations using the belongsToMany method in the chat model. There, we can directly provide an array ...
Read now
Unlock full access