Best practices for sending cursor to client

I’m using Fauna via a server that implements API (and not directly from the client).
Is there a best-practice how to send after/before cursors to the client?
I don’t like their form because:

  1. They are JSON object and not simple string that you can easily add to query param
  2. They expose the internal structure of your DB like collection or index names

I thought maybe strip the unnecessary clutter and stay just with IDs, and then base64 encode it.
E.g. this cursor:

   Ref(Collection("FormSubmits"), "277377102731280915"),
   Ref(Collection("FormSubmits"), "277377102731280915")

will become:


and after encoding


On the decode side I’ll have to have the logic that the first item in the array has to be wrapped with Time(X),the second and third with Ref(Collection("FormSubmits"), X)

So it doesn’t solve #2 fully, just hides it from the naked eye, and also requires custom implementation.
Is there any other way that is recommended?


1 Like

I have used a serialized base64 string for a few years already and I’m happy with that. If you keep it simple and decode/parse with the parseJSON function from the fauna js driver you have something that works whatever the shape of your index might be. Here is the implementation I use in our custom GraphQL api:

1 Like

Thanks, @eigilsagafos
What’s the benefit of parseJSON over native JSON.parse ?

If the index contains Refs the parseJSON from the fauna lib casts to the correct types.

1 Like