Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cainlevy/typeorm-relay-connection
TypeORM implementation of the Relay Connection spec
https://github.com/cainlevy/typeorm-relay-connection
Last synced: 24 days ago
JSON representation
TypeORM implementation of the Relay Connection spec
- Host: GitHub
- URL: https://github.com/cainlevy/typeorm-relay-connection
- Owner: cainlevy
- License: gpl-3.0
- Created: 2022-11-09T21:10:15.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-26T16:06:37.000Z (3 months ago)
- Last Synced: 2024-07-27T17:49:01.078Z (3 months ago)
- Language: TypeScript
- Size: 526 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## TypeORM Relay Connection
TypeORM implementation of Relay Connection spec.
## Getting Started
Install:
```
npm install typeorm-relay-connection
```### GraphQL Resolver
```js
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:
```graphql
query {
books {
total
edges {
node {
id
name
}
}
}
}
``````js
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.