ash-project / ash_json_api

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

add ability to supply custom route metadata #152

Closed jsw800 closed 3 months ago

jsw800 commented 3 months ago

Contributor checklist

👋🏻

Coming from Discord, thread

The idea here is to add a metadata option to each route that allows users to control the top-level meta of that route:

routes do
  index :read do
    metadata fn query, results, request ->
      %{"my" => "custom", "metadata" => "here"}
    end
  end
end

would result in

{
  "data": <...>,
  "links": [<...>],
  "meta": {
    "my": "custom",
    "metadata": "here",
    <...any builtin metadata such as page metadata>
  }
}

The main part of this PR that I'm a little unsure on is how I'm grabbing the query/changeset in helpers.ex. It seems like each route type has its own somewhat complex custom logic in there, and I'm not 100% sure that I've gotten the correct query/changeset in each scenario. This is my first substantive contribution here so I'm very open to feedback, I'm sure there's things to improve on here!

zachdaniel commented 3 months ago

🚀 Thank you for your contribution! 🚀