AbsintheRelayKeysetConnection.CursorTranslator.Base64Hashed (absinthe_relay_keyset_connection v2.0.0)

View Source

A cursor translator implementation that uses base64 and a hashed padding.

A tamper-resistant (not tamper-proof) implementation that uses base64 and a hashed padding.

These values are serialized using Jason.encode/1, which means you'll need an implementation of the Jason.Encoder protocol for the type of each column you sort by. The library covers most common data types, but you may need to implement your own for less common ones.

For example, if you're using Postgrex.INET for a PostgreSQL inet column, you might need:

defmodule MyApp.CustomEncoders do
 defimpl Jason.Encoder, for: [Postgrex.INET] do
   def encode(struct, opts) do
     Jason.Encode.string(EctoNetwork.INET.decode(struct), opts)
   end
 end
end

Summary

Functions

Creates the cursor string from a key. This encoding is not meant to be tamper-proof, just to hide the cursor data as an implementation detail.

Rederives the key from the cursor string. The cursor string is supplied by users and may have been tampered with. However, we ensure that only the expected column values may appear in the cursor, so at worst, they could paginate from a different spot, which is fine.

Functions

from_key(key_map, cursor_columns)

Creates the cursor string from a key. This encoding is not meant to be tamper-proof, just to hide the cursor data as an implementation detail.

Examples

iex> from_key(%{id: 25}, [:id])
"Tr7wn5SRWzI1XQ=="

iex> from_key(%{name: "Mo", id: 26}, [:name, :id])
"eo7wn5SRWyJNbyIsMjZd"

to_key(encoded_cursor, expected_columns)

Rederives the key from the cursor string. The cursor string is supplied by users and may have been tampered with. However, we ensure that only the expected column values may appear in the cursor, so at worst, they could paginate from a different spot, which is fine.

Examples

iex> to_key("Tr7wn5SRWzI1XQ==", [:id])
{:ok, %{id: 25}}