[CORL-325] Comment Search API (#2578)

* feat: added comment search support

* fix: updated readme

* Update README.md
This commit is contained in:
Wyatt Johnson
2019-10-01 18:57:50 +00:00
committed by GitHub
parent c045f52daa
commit 53fa5f43e5
4 changed files with 51 additions and 5 deletions
@@ -48,6 +48,14 @@ const tagFilter = (tag?: GQLTAG): CommentConnectionInput["filter"] => {
return {};
};
const queryFilter = (query?: string): CommentConnectionInput["filter"] => {
if (query) {
return { $text: { $search: `"${query}"` } };
}
return {};
};
/**
* primeCommentsFromConnection will prime a given context with the comments
* retrieved via a connection.
@@ -123,6 +131,7 @@ export default (ctx: Context) => ({
storyID,
status,
tag,
query,
}: QueryToCommentsArgs) =>
retrieveCommentConnection(ctx.mongo, ctx.tenant.id, {
first,
@@ -130,6 +139,7 @@ export default (ctx: Context) => ({
orderBy: GQLCOMMENT_SORT.CREATED_AT_DESC,
filter: omitBy(
{
...queryFilter(query),
...tagFilter(tag),
storyID,
status,
@@ -2523,6 +2523,7 @@ type Query {
storyID: ID
status: COMMENT_STATUS
tag: TAG
query: String
): CommentsConnection! @auth(roles: [ADMIN, MODERATOR])
"""