diff --git a/package.json b/package.json index eba09ba..290609d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.23.1", + "version": "0.23.2", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/modules/messages/index.ts b/src/modules/messages/index.ts index 719312f..f65de0f 100644 --- a/src/modules/messages/index.ts +++ b/src/modules/messages/index.ts @@ -225,6 +225,10 @@ export class Messages { orderBy?: Array; first?: number; page?: number; + childrenOptions?: { + alias?: string; // Alias for the children field + first?: number; // Limit for children + }; } = {} ): Promise { const { @@ -232,11 +236,15 @@ export class Messages { channel_slug, where, orderBy, - first, + first = 25, page, + childrenOptions = {}, } = options; + + const { alias = 'children', first: childrenFirst } = childrenOptions; + const response = await this.client.query({ - query: GET_CHANNEL_MESSAGES_QUERY, + query: GET_CHANNEL_MESSAGES_QUERY(childrenFirst !== undefined, alias), variables: { channel_uuid, channel_slug, @@ -244,9 +252,11 @@ export class Messages { orderBy, first, page, + ...(childrenFirst !== undefined && { childrenFirst }), }, fetchPolicy: 'no-cache', }); + return response.data; } diff --git a/src/queries/messages.query.ts b/src/queries/messages.query.ts index 9a186a0..0fc2191 100644 --- a/src/queries/messages.query.ts +++ b/src/queries/messages.query.ts @@ -273,7 +273,7 @@ export const GET_MESSAGES_BY_DISPLAYNAME_AND_SLUG = gql` } `; -export const GET_CHANNEL_MESSAGES_QUERY = gql` +export const GET_CHANNEL_MESSAGES_QUERY = (includeChildren: boolean, alias: string) => gql` query channelMessages( $channel_uuid: String $channel_slug: String @@ -281,6 +281,7 @@ export const GET_CHANNEL_MESSAGES_QUERY = gql` $orderBy: [QueryChannelMessagesOrderByOrderByClause!] $first: Int! = 25 $page: Int + ${includeChildren ? `$childrenFirst: Int!` : ''} ) { channelMessages( channel_uuid: $channel_uuid @@ -335,6 +336,23 @@ export const GET_CHANNEL_MESSAGES_QUERY = gql` is_reported is_purchased } + ${includeChildren ? `${alias}: children(first: $childrenFirst) { + data { + id + uuid + message + slug + user { + id + firstname + lastname + displayname + photo { + url + } + } + } + }` : ''} created_at } paginatorInfo {