Enabling relay for a resource sets it up to follow the relay specification .
The two changes that are made currently are:
the type for the resource will implement the
- pagination over that resource will behave as a Connection.
Use the following option when calling
use AshGraphql, define_relay_types?: false
Use the following option to generate Relay Global IDs (see here ).
use AshGraphql, relay_ids?: true
This allows refetching a node using the
node query and passing its global ID.
relay_ids?: true is passed, users of the API will have access only to the global IDs, so they
will also need to use them when an ID is required as argument. You actions, though, internally use the
normal IDs defined by the data layer.
To handle the translation between the two ID domains, you can use the
relay_id_translations option. With this, you can define a list of arguments that will be translated from Relay global IDs
to internal IDs.
For example, if you have a
Post resource with an action to create a post associated with an
create :create do
argument :author_id, :uuid
# Do stuff with author_id
You can add this to the mutation connected to that action:
create :create_post, :create do
relay_id_translations [input: [author_id: :user]]