I've looked through all of Relay's documentation and there doesn't seem to be a straightforward explanation on how to build a Relay connection with an ORM. All the examples seem to use the connectionFromArray
method which is fine if you're storing your data in memory but when you're storing the data in a database how would you go about providing the information necessary for a connection's pagination to work?
The cursor is opaque:
The result of this field is considered opaque by Relay, but will be passed back to the server as described in the "Arguments" section below.
So, depending on your data model, it may be appropriate to pass something as simple as an ID string as a cursor, which you could then use on the server to load the connection using a clause like WHERE id > ?
. You could pack arbitrary info in here necessary for pagination here and Base-64 encode it, for example.
It you look at the code which returns a connection from an array, you'll get a rough idea of the semantics you'll need do implement on top of your ORM-backed storage, but instead of indexing into the array like it does, you'll be synthesizing an opaque cursor that contains enough info to do subsequent pagination with your ORM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With