Overview
The RealtimeChat GraphQL API provides queries to fetch chat rooms and messages. All queries are available through the rootQuery type.
GetChatRoom
Retrieve a single chat room by its ID, including all associated messages.Parameters
The unique identifier of the chat room to retrieve
Return Type
ChatRoomGraph - A chat room object with all its messages
GraphQL Schema
Example Query
Example Response
This query will throw an error if the chat room with the specified ID does not exist.
GetChatRooms
Retrieve all available chat rooms. This query returns anIQueryable that supports filtering and pagination.
Parameters
This query accepts no required parameters but supports HotChocolate’s built-in filtering and pagination:Limit the number of results (pagination)
Cursor for forward pagination
Filter chat rooms by criteria
Return Type
[ChatRoomGraph!]! - An array of chat room objects
GraphQL Schema
Example Query
Example with Pagination
Example Response
GetMessages
Retrieve all messages from a specific chat room, ordered by send time.Parameters
The ID of the chat room to fetch messages from
Return Type
[MessageGraph!]! - An array of message objects ordered by sentAt (ascending)
GraphQL Schema
Example Query
Example Response
Messages are automatically ordered by
sentAt in ascending order (oldest first).GetFilteredMessages
Search for messages containing specific text within a chat room. This uses PostgreSQL’s trigram similarity for efficient text search.Parameters
The ID of the chat room to search within
The text to search for in message content
Return Type
[MessageGraph!]! - An array of matching message objects ordered by sentAt
GraphQL Schema
Example Query
Example Response
The search uses PostgreSQL trigram similarity for fuzzy matching, which can find similar text even with minor typos.
Types Reference
ChatRoomGraph
Unique identifier for the chat room
Display name of the chat room
Array of all messages in the chat room
MessageGraph
Unique identifier for the message
Timestamp when the message was sent (ISO 8601 format)
Identifier of the user who sent the message
ID of the chat room this message belongs to
The message content (union type supporting text and images)
MessageContent (Union)
TheMessageContent is a GraphQL union type that can be:
Source Code Reference
The queries are implemented in:Infrastructure/RealtimeChat.Infrastructure.GraphQL/Queries/Query.cs
Infrastructure/RealtimeChat.Infrastructure.GraphQL/Models/ChatRoomGraph.csInfrastructure/RealtimeChat.Infrastructure.GraphQL/Models/MessageGraph.cs