Skip to content

Instantly share code, notes, and snippets.

@pixeldrew
pixeldrew / cursor-helper.js
Last active January 19, 2022 22:21 — forked from pcattori/gist:2bb645d587e45c9fdbcabf5cef7a7106
relay-style cursor-based pagination capable of filtering/sorting for SQL
const { Base64 } = require('js-base64')
const { Op } = require('sequelize');
// https://github.com/graphql/graphql-relay-js/issues/94#issuecomment-232410564
const effectiveOrder = ({ last }, orderBy) => {
/* adds `id ASC` to end of `ORDER BY` if `id` is not already in the `ORDER BY` clause
flips `ASC` to `DESC` (and vice-versa) if pagination arg `last` is defined
*/
const order = orderBy