Description
QueryQL makes it easy to add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string! QueryQL works with any Node.js web framework (be it Express, Koa, etc.), supports any query builder / ORM through adapters, and allows for custom validators so you can define validation in a familiar way.
QueryQL alternatives and similar modules
Based on the "Web Frameworks" category.
Alternatively, view QueryQL alternatives based on common mentions on social networks and blogs.
-
Nest
A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript ๐ -
Nuxt.js
DISCONTINUED. Nuxt is an intuitive and extendable way to create type-safe, performant and production-grade full-stack web apps and websites with Vue 3. [Moved to: https://github.com/nuxt/nuxt] -
AdonisJs Framework
AdonisJS is a TypeScript-first web framework for building web apps and API servers. It comes with support for testing, modern tooling, an ecosystem of official packages, and more. -
Quick Start
๐ A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. ๐ -
Encore
Development Platform for building robust type-safe distributed systems with declarative infrastructure -
Derby
MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers -
NestJS REST API boilerplate
NestJS boilerplate. Auth, TypeORM, Mongoose, Postgres, MongoDB, Mailing, I18N, Docker. -
ActionHero
Actionhero is a realtime multi-transport nodejs API Server with integrated cluster capabilities and delayed tasks -
Lad
Node.js framework made by a former @expressjs TC and @koajs team member. Built for @forwardemail, @spamscanner, @breejs, @cabinjs, and @lassjs. -
Marble.js
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS. -
FoalTS
Full-featured Node.js framework, with no complexity. ๐ Simple and easy to use, TypeScript-based and well-documented. -
lychee.js
DISCONTINUED. :seedling: Next-Gen AI-Assisted Isomorphic Application Engine for Embedded, Console, Mobile, Server and Desktop -
Hemera
๐ฌ Writing reliable & fault-tolerant microservices in Node.js https://hemerajs.github.io/hemera/ -
Catberry
Catberry is an isomorphic framework for building universal front-end apps using components, Flux architecture and progressive rendering. -
dawson-cli
DISCONTINUED. A serverless web framework for Node.js on AWS (CloudFormation, CloudFront, API Gateway, Lambda) -
AdonisJs Application
DISCONTINUED. This repo is the pre-configured project structure to be used for creating ambitious web servers using AdonisJs. -
express-version-route
A Node.js express middleware that implements API versioning for route controllers -
FortJs
A feature-rich Node.js web framework designed for building powerful, scalable, and maintainable web applications. -
Prim+RPC
Easy-to-understand, type-safe, transport-agnostic RPC/IPC for JavaScript, supporting callbacks, batching, file handling, custom serialization, and more.
InfluxDB - Purpose built for real-time analytics at any scale.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of QueryQL or a related project?
README
QueryQL
QueryQL makes it easy to add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string! Read our introductory article to learn more about why we wrote it and the problems it solves at Truepic.
QueryQL works with any Node.js web framework (be it Express, Koa, etc.), supports any query builder / ORM through adapters, and allows for custom validators so you can define validation in a familiar way.
Out of the box, QueryQL supports the following:
- Adapter: Knex (works with Objection.js and other ORMs that use Knex)
- Validator: Joi
Installation
$ npm install @truepic/queryql
Getting Started
QueryQL takes a parsed query string (like Express' req.query
) and translates
it into the appropriate function calls that your query builder / ORM understands
to filter, sort, and paginate the records.
Let's consider an example to illustrate:
/images?filter[id][in][]=2&filter[id][in][]=3&filter[status]=open&sort=name&page[size]=10
{
filter: {
id: {
in: [2, 3],
},
status: 'open',
},
sort: 'name',
page: {
size: 10,
},
}
To support this query, QueryQL only requires you to define (whitelist) what's
allowed through what we call a querier. Here's how one might look for the
/images
endpoint:
const QueryQL = require('@truepic/queryql')
class ImageQuerier extends QueryQL {
defineSchema(schema) {
schema.filter('id', 'in')
schema.filter('status', '=')
schema.sort('name')
schema.page()
}
}
With your querier defined, you can now call it in your router / controller. Here's how it might look in an Express route:
app.get('/images', async (req, res, next) => {
const querier = new ImageQuerier(req.query, knex('images'))
let images
try {
images = await querier.run()
} catch (error) {
// Handle validation error, such as by passing to an Express error handler:
next(error)
}
res.send({ images })
})
Behind-the-scenes, QueryQL takes your initial query builder (knex('images')
),
and applies the following Knex chain when querier.run()
is called:
builder
.where('id', 'in', [2, 3])
.where('status', '=', 'open')
.orderBy('name', 'asc')
.limit(10)
.offset(0)
(Remember: While Knex is our default adapter and the query builder used in this example, adapters can be written for any query builder / ORM.)
This is a simple example, but hopefully it illustrates how easy it is to add filtering, sorting, and pagination to your REST API without manually touching your query builder / ORM.
[Read the full documentation](DOCS.md) to learn how to add validation, customize the queries, and more.
Development
Prerequisites
The only prerequisite is a compatible version of Node.js (see engines.node
in
package.json
).
Dependencies
Install dependencies with npm:
$ npm install
Tests
Jest is our testing framework of choice. We strive for 100% code coverage.
To run the tests:
$ npm test
During development, it's recommended to run the tests automatically on file change:
$ npm test -- --watch [--notify]
Code Style & Linting
Prettier is setup to enforce a consistent code style. It's highly recommended to add an integration to your editor that automatically formats on save.
ESLint is setup with the "recommended" rules to enforce a level of code quality. It's also highly recommended to add an integration to your editor that automatically formats on save.
To run via the command line:
$ npm run lint
Releasing
After development is done in the development
branch and is ready for release,
it should be merged into the master
branch, where the latest release code
lives. Release It! is then used to
interactively orchestrate the release process:
$ npm run release