Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact/channel-query #367

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.23.1",
"version": "0.23.2",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
14 changes: 12 additions & 2 deletions src/modules/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,28 +225,38 @@ export class Messages {
orderBy?: Array<OrderByMessage>;
first?: number;
page?: number;
childrenOptions?: {
alias?: string; // Alias for the children field
first?: number; // Limit for children
};
} = {}
): Promise<AllChannelMessages> {
const {
channel_uuid,
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,
where,
orderBy,
first,
page,
...(childrenFirst !== undefined && { childrenFirst }),
},
fetchPolicy: 'no-cache',
});

return response.data;
}

Expand Down
20 changes: 19 additions & 1 deletion src/queries/messages.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,15 @@ 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
$where: QueryChannelMessagesWhereWhereConditions
$orderBy: [QueryChannelMessagesOrderByOrderByClause!]
$first: Int! = 25
$page: Int
${includeChildren ? `$childrenFirst: Int!` : ''}
) {
channelMessages(
channel_uuid: $channel_uuid
Expand Down Expand Up @@ -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 {
Expand Down
Loading