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

[Feature] Filter quests #202

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/directives/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default function paginationDirective(directiveName: string): DirectiveTra
limitQueryWithId(
query,
args.before,
args.after
args.after,
args.filter
);
const pageInfo = await applyPagination(
query, args.first, args.last
Expand Down
16 changes: 14 additions & 2 deletions src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface PaginationArguments {
* Number of requested nodes before a node with a cursor in the `before` argument
*/
last?: number;

/**
*
ilyamore88 marked this conversation as resolved.
Show resolved Hide resolved
*/
filter?: FilterQuery<unknown>;
}

/**
Expand Down Expand Up @@ -86,24 +91,31 @@ export interface Connection<T> {
* @param query - mongodb cursor to handle
* @param before - the cursor after before we take the data
* @param after - the cursor after which we take the data
* @param queryFilter - filter for query provided by user
*/
export function limitQueryWithId(query: Cursor, before?: string, after?: string): Cursor {
export function limitQueryWithId(query: Cursor, before?: string, after?: string, queryFilter?: FilterQuery<any>): Cursor {
let filter: FilterQuery<PersonDBScheme>;

if (before) {
filter = {
...queryFilter,
_id: {
...queryFilter?._id,
$lt: new ObjectId(before),
},
};
} else if (after) {
filter = {
...queryFilter,
_id: {
...queryFilter?._id,
$gt: new ObjectId(after),
},
};
} else {
filter = {};
filter = {
...queryFilter,
};
ilyamore88 marked this conversation as resolved.
Show resolved Hide resolved
}

return query.filter(filter);
Expand Down
5 changes: 5 additions & 0 deletions src/typeDefs/quests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ export default gql`

"Number of requested nodes before a node with a cursor in the before argument"
last: Int

"""
Filter query results
"""
filter: JSON
): QuestConnection! @pagination(collectionName: "quests")
}
`;