Now that we are squared with Mongoose models, it's time to move to the core functionality in the app, that is creating chats and sending messages. In this video, we will enable members to start conversations with other users, and in the next episode, we will implement relationships between GraphQL types via query population.
When starting a chat, the API consumer needs to indicate the IDs of the participants that they'd want to include in the exchange. This necessitates us to validate an array of strings as Object IDs, which joi does not provide for out of the box. Luckily, it's easy to extend joi with custom validators https://github.com/hapijs/joi/blob/v1... We could either use an existing module (such as https://www.npmjs.com/package/@wegolo... from NPM) or write our own. For demo purposes, we'll go with the later.
To make it simple, we'll ask the client not to provide their own ID in the list. When it's time to feed the IDs via insert on Chat, we'll push the signed in user's ID ourselves. This is the easiest workaround that keeps the business logic straightforward and the code clean.
Next time around, we'll begin populating related models so that users can issue nested queries in the API. See you then!
Смотрите видео MERN Stack & GraphQL - #14 Creating a Chat онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Code Realm 20 Январь 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 6,60 раз и оно понравилось 7 людям.