Overview
TheChatRoom model represents a conversation space where multiple users can exchange messages. Each chat room has a unique identifier, a name, and contains collections of messages and participants.
Model Purpose
ChatRooms serve as the primary organizational unit for conversations in the RealtimeChat application. They:- Group related messages together
- Define the scope of real-time subscriptions
- Manage participant membership
- Provide context for message delivery
Properties
Unique identifier for the chat room.
Display name for the chat room. Used in UI to identify the conversation.
Collection of all messages posted in this chat room.
Relationships
Messages
Each chat room has a one-to-many relationship with messages. Messages are automatically associated with their parent chat room through theChatRoomId foreign key.
The GraphQL API returns messages with each chat room, but participant information is managed separately in the database layer and not exposed through the current GraphQL schema.
GraphQL Type Definition
The GraphQL representation includes
Id, Name, and the nested Messages collection. Participants are managed separately through dedicated queries and mutations.Example JSON Representation
Database Schema
The chat room is persisted using theChatRoomEntity class:
The database schema includes navigation properties for both
Messages and ChatRoomParticipants to support efficient querying and eager loading.Usage in GraphQL
Chat rooms are the primary entry point for querying conversation data:Best Practices
- Naming: Use descriptive, user-friendly names for chat rooms
- Participants: Always verify user membership before allowing message posting
- Message Loading: Consider pagination for chat rooms with large message histories
- Real-time Updates: Subscribe to chat room updates to receive new messages immediately