a full stack enthusiast interested in Javascript / Typescript / Kotlin / Python / React / React Native / (Android & iOS) native / Cloud
How to use Relay style pagination in TypeGraphql
Posted onEdited onDisqus:
I am quite into Relay these days, for its opinionated, typesafe and performant approach. Especially for the effortless pagination.
For the backend, I use TypeGraphql, so easy to pick up if you already familiar with Typscript, typesafe, explicit, code-first, and very fast even it uses a js class approach. Today, I will show you how to define the Relay connection in TypeGraphql. I am using v1.0.0 here.
It’s not about actual implementation, since it is related to your data access layer. This blog is purely focused on defining the TypeGraphql class and how to use them.
@Field((type) =>String, { description: "Used in `before` and `after` args", }) cursor: Relay.ConnectionCursor; }
returnEdge; }
You may wonder why EdgeType? It is because of the convenience of doing Relay Store update later. If you return a EdgeType after mutation, you can insert the response into the local connection directly, otherwise, you have to create the edge by yourself, which doesn’t sound very interesting.
Here, due to the limited reflection capabilities of TypeScript, you can’t use the normal Typescript type for generic. The documentation is here is you want to learn more. So every time you want to use generic in TypeGraphql, you have to use this way.