1.0.2 • Published 1 year ago

typeorm-relay-connection v1.0.2

Weekly downloads
-
License
GPL-3.0
Repository
-
Last release
1 year ago

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.

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago