ash-project / ash-project/ash_graphql
Add support for Relay refetching (Relay-compliant IDs and the `Node` query)
- Dominant language
- Elixir
- Stars
- 97
- Forks
- 101
- Avg merge
- 12h 51m
- Merged PRs (30d)
- 5
Description
**Is your feature request related to a problem? Please describe.**
Ash GraphQL implements the Relay Node interface, but Relay refetching mechanism assumes that IDs are globally unique (and, basically, encode enough information to retrieve a specific object given only its ID), while currently Ash GraphQL returns the data layer primary key (possibly encoded if multiple), that even if globally-unique (e.g. UUID) still doesn't contain enough information to target a specific resource on a data layer. Moreover, Relay assumes there's a root `Node` query .
**Describe the solution you'd like**
It should be possible to use the Node refetch mechanism with Ash GraphQL.
**Describe alternatives you've considered**
Passing `define_relay_types?: false` (found on a discussion on Discord) doesn't really do much because while it allows you to manually define the `node` interface, it still doesn't give access to the extension points needed to handle the ID encoding/decoding.
**Express the feature either with a change to resource syntax, or with a change to the resource interface**
I guess this would make sense globally, so I imagine something like:
```elixir
use AshGraphQL, relay_ids?: true
```
I'm not sure if this should be a separate option or should take the values from `define_relay_types?` in the long run, but clearly it makes sense to have a separate variable until the next major.
This would take care of generating the blueprints to both encode to and decode from the `:id` field, embedding resource type + primary key informations.
The other aspect of this is that sometimes mutations (also queries?) can take as argument an ID to another object. For that I think that some more separate syntax has to be added explicitly marking the arguments that need to be translated:
```elixir
update :frobnicate_with_the_foobar, :update, relay_ids: [:foobar_id]
```
I can try to tackle this if the rough plan sounds good, or let me know if I'm missing some details.
Contributor guide
Research direction
Start by reviewing the AshGraphQL Relay support around define_relay_types? and the generated Node query, then trace how resource primary keys are currently encoded. Define what Relay-compliant IDs, decoding, root Node lookup, and mutation argument translation must do, and verify the behavior with coverage for refetching and related IDs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir, graphql
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100