TypeORM implementation of Relay Connection spec.
Install:
npm install typeorm-relay-connection
const QueryResolver = {
books: async (_, args, { db }) =>
new TypeORMRelayConnection(
// query builder with some number of requirements
db.createQueryBuilder(Book, "book").where("published_at IS NOT NULL"),
// standard relay arguments from client
args,
// configuration
{
// constraint on args.first and args.last
// default: 500
limit: 100,
// primary (unique!) key for Book
// default: 'id'
cursorKey: "id",
// desired sorting for pagination order
// default: 'created_at'
sortingKey: "published_at",
// default: 'ASC'
sortingOrder: "ASC",
}
),
};
You can access the scope from connection resolvers to calculate aggregates on whatever query was previously built for pagination:
query {
books {
total
edges {
node {
id
name
}
}
}
}
const BookConnectionResolver = {
// parent is the TypeORMRelayConnection from BookResolver.books
total: async (parent) => await parent.scope.getCount(),
};
- Review
CHANGELOG.md
and determine the next semantic version - Commit a change to
package.json
andCHANGELOG.md
with the next version. Push. - Tag the commit. Push tags.
- Run
npm publish
Bug reports and pull requests are welcome! This project is intended to be a safe, welcoming space for collaboration.