typeorm-relay-connection
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

TypeORM Relay Connection

TypeORM implementation of Relay Connection spec.

Getting Started

Install:

npm install typeorm-relay-connection

GraphQL Resolver

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",
      }
    ),
};

Connection Aggregates

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(),
};

Releasing

  1. Review CHANGELOG.md and determine the next semantic version
  2. Commit a change to package.json and CHANGELOG.md with the next version. Push.
  3. Tag the commit. Push tags.
  4. Run npm publish

Contributing

Bug reports and pull requests are welcome! This project is intended to be a safe, welcoming space for collaboration.

Readme

Keywords

none

Package Sidebar

Install

npm i typeorm-relay-connection

Weekly Downloads

34

Version

1.0.3

License

GPL-3.0

Unpacked Size

49 kB

Total Files

9

Last publish

Collaborators

  • cainlevy