-
Notifications
You must be signed in to change notification settings - Fork 86
Replace jaserializer with jsonapi #1140
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
Conversation
has_many :project_categories, serializer: CodeCorpsWeb.ProjectCategoryView, identifiers: :always | ||
def fields, do: [:name, :slug, :description] | ||
def type, do: "category" | ||
def relationships, do: [project_categories: CodeCorpsWeb.ProjectCategoryView] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will also try includes
for relationships once we figure out how to use this lib.
|
||
attributes [:name, :slug, :description] | ||
def render("show.json-api", %{ data: category, conn: conn, params: params }) do | ||
__MODULE__.show(category, conn, params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
params
is an unused arg to the show
function. Candidate for a PR to the lib.
def show(%Conn{} = conn, %{"id" => id}) do | ||
with %Category{} = category <- Category |> Repo.get(id) |> preload() do | ||
conn |> render("show.json-api", data: category) | ||
conn |> render(CodeCorpsWeb.CategoryView, "show.json-api", %{ data: category, conn: conn, params: id }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can just call the show
action provided by the jsonapi lib instead of calling render....?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems plausible. Have you tried this?
First step. Unless my understanding is off, I am not sure if the lib could be improved for handling relationships. It seems like it requires preloading all relationships down the tree when. So for example, serializing Lmk if anybody sees it otherwise. |
Based on some of the perf findings with lots of tasks for a task_list view shown in the issue, was given the green light to work on |
Ref #1139
This is a very initial commit using jsonapi. Can try it out by running
category_view_test.exs
.Essentially, this lib gives us a
show
andindex
function for which we can call.Couple of things.
2. We use dasherized plural types. The dasherized config is not working for relationships right now.Solved with master branchTODO: