devoxa/prisma-relay-cursor-connection

Extend types to allow models with numeric IDs

queicherius opened this issue · 4 comments

Right now the model has to have { id: string }, because I could not get the generic types working for { id: string | number }

Contributions welcome

Hi
How about converting a cursor object to a base64 string?

Because prisma has various types of cursors like multi-field ID or unique field

Check out my implementation of fork
https://github.com/jeongsd/prisma-relay-cursor-connection

If you like this then I will create PR

Hey @jeongsd - first off thanks for the interest in the repository!

I had a look at your implementation, and I like the idea of being able to pass in a function that picks which kind of cursor you would like.

As for converting the cursor to base64, I am not sure. We should probably not do that by default - maybe via another function the user can pass in? As an example for why, I use this module using NestJS, and a custom Cursor GraphQL scalar, which already does encoding/decoding/validating before ever hitting the service code that this module is executed in.

I could imagine an API like this, with options being optional and defaulting to what is currently the default (id, no encoding/decoding).

export async function findManyCursorConnection(
  findMany,
  aggregate,
  args,
  options?: {
    getCursor,
    encodeCursor,
    decodeCursor
  }
) {	)

@queicherius thank you for the reply!

Sounds like a good idea to use custom Cursor GraphQL scalar.

I will create PR by reflecting on your ideas.

Released in 1.1.0