Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Relay refetching (Relay-compliant IDs and the Node query) #99

Open
rbino opened this issue Nov 24, 2023 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@rbino
Copy link
Contributor

rbino commented Nov 24, 2023

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:

  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:

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.

@rbino rbino added the enhancement New feature or request label Nov 24, 2023
@zachdaniel
Copy link
Contributor

Your plan sounds exactly correct 🤌

@rbino
Copy link
Contributor Author

rbino commented Jan 15, 2024

@zachdaniel I was circling back around this, and I've realized it probably makes more sense to define this per-resource instead of globally. Absinthe itself requires to add the node macro in front of each object that implements the Node interface.

This would also unlock the possibility of custom ID fetchers (as Absinthe does) if one wants to implement them. The downside of this is that it's a little more verbose.

@zachdaniel
Copy link
Contributor

Hmmm...potentially. I'd suggest we should start with a global version that requires no configuration, and then allow for overriding if necessary.

rbino added a commit to rbino/ash_graphql that referenced this issue Jan 18, 2024
Part 1 of what is needed for ash-project#99.
The other half is implementing the node query.
rbino added a commit to rbino/ash_graphql that referenced this issue Jan 18, 2024
Part 1 of what is needed for ash-project#99.
The other half is implementing the node query.
rbino added a commit to rbino/ash_graphql that referenced this issue Jan 22, 2024
Part 1 of what is needed for ash-project#99.
The other half is implementing the node query.
rbino added a commit to rbino/ash_graphql that referenced this issue Jan 22, 2024
Allow refetching a resource given it Relay global ID.
Close ash-project#99.
rbino added a commit to rbino/ash_graphql that referenced this issue Jan 22, 2024
Part 1 of what is needed for ash-project#99.
The other half is implementing the node query.
rbino added a commit to rbino/ash_graphql that referenced this issue Jan 22, 2024
Allow refetching a resource given it Relay global ID.
Close ash-project#99.
rbino added a commit to rbino/ash_graphql that referenced this issue Jan 24, 2024
Allow retrieving a resource implementing the Node interface given its Relay
global id.

Close ash-project#99
rbino added a commit to rbino/ash_graphql that referenced this issue Jan 24, 2024
Allow retrieving a resource implementing the Node interface given its Relay
global id.

Close ash-project#99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants