ash-project / ash_json_api

The JSON:API extension for the Ash Framework
https://hexdocs.pm/ash_json_api
MIT License
55 stars 41 forks source link

Missing links for related relationship data #168

Closed sevenseacat closed 1 month ago

sevenseacat commented 1 month ago

Describe the bug

The example for compound documents and relationships in the JSON:API docs show that we should be providing links for how to fetch related data, if they exist.

eg.

This is important for discoverability of relationships in the API.

To Reproduce

For an Artist resource defined like so:

  json_api do
    type "artist"

    routes do
      base "/artists"
      get :read
      related :albums, :read
    end
  end

An API response to get an artist returns the following relationship data:

    "relationships": {
      "albums": {
        "links": {},
        "meta": {}
      }
    }

Expected behavior

I would expect the links in the relationship data to include a related link like:

{
  "links": {
    "related": "http://localhost:4000/api/artists/the_artist_id/albums"
  }
}

In a similar/related vein, I'd expect the links for included resources to be populated with self links.

Runtime

zachdaniel commented 1 month ago

Alright, so this one was primarily a documentation issue. I've added a very high level guide for this, as I'm a bit low on time today. It does, however, explain that links are generated from primary? routes. So to have your links generated, you'd want to designate the appropriate routes as primary? true

sevenseacat commented 1 month ago

I didn't even know that was an option! cheers 👍