@tedbir/graphql-query-kit
v1.0.1
Published
Reusable GraphQL filtering, sorting, and pagination helpers for NestJS + MongoDB.
Readme
@tedbir/graphql-query-kit
Reusable GraphQL filtering, sorting, and pagination helpers for NestJS + MongoDB.
Install
npm i @tedbir/graphql-query-kitQuick start
import {
CursorPaginationInput,
FilterInput,
SearchInput,
SortInput,
applyQuery,
} from '@tedbir/graphql-query-kit';
const fieldMap = {
name: { type: 'string' },
createdAt: { type: 'date' },
};
// Example resolver/service usage
return applyQuery(model, {}, fieldMap, filter, sort, pagination, search, {
cursorField: 'createdAt',
searchFields: ['name'],
select: ['name', 'createdAt'],
});Full guide: USAGE.md
Build (package)
npm run buildUsage
import {
CursorPaginationInput,
FilterInput,
SearchInput,
SortInput,
applyQuery,
applyQueryWithPageInfo,
PageInfo,
FilterOperator,
FilterLogic,
SortDirection,
} from '@tedbir/graphql-query-kit';applyQueryWithPageInfo returns { items, pageInfo } where pageInfo includes
hasNextPage, hasPreviousPage, nextCursor, and prevCursor.
Full guide: USAGE.md
Notes
- The package keeps
@/aliases in source and rewrites them to relative paths on build viatsc-alias. - Enums register themselves with GraphQL on import.
- Cursor pagination supports any sort field. If the sort field differs from
cursorField, the cursor becomes a composite (sort value + cursorField value) and is returned viapageInfo.nextCursor/pageInfo.prevCursor.
