-
Notifications
You must be signed in to change notification settings - Fork 78
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
Query parameters in self url #224
Query parameters in self url #224
Conversation
} | ||
} | ||
} | ||
|> Plug.Conn.fetch_query_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.
👋 Why is this needed? Is there an assertion we could add for a similar example you had in the PR description?
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.
Why is this needed?
Because, otherwise, the query_params
field of the connection is a Plug.Conn.Unfetched
struct, and JSONAPI.View.url_for_pagination/3
fails with the following error.
1) test with a dasherized API handles sparse fields properly (JSONAPITest)
test/jsonapi_test.exs:328
** (Protocol.UndefinedError) protocol Enumerable not implemented for %{:__struct__ => Plug.Conn.Unfetched, :aspect => :query_params, "page" => %{}} of type Plug.Conn.Unfetched (a struct). This protocol is implemented for the following type(s): HashSet, Range, Map, Function, List, Stream, Date.Range, HashDict, GenEvent.Stream, MapSet, File.Stream, IO.Stream
code: |> MyPostPlug.call([])
stacktrace:
(elixir 1.10.2) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir 1.10.2) lib/enum.ex:141: Enumerable.reduce/3
(elixir 1.10.2) lib/enum.ex:3383: Enum.flat_map/2
test/jsonapi_test.exs:14: JSONAPITest.PostView.url_for_pagination/3
(jsonapi 1.2.3) lib/jsonapi/serializer.ex:178: JSONAPI.Serializer.merge_links/7
test/jsonapi_test.exs:86: JSONAPITest.MyPostPlug.passthrough/2
test/jsonapi_test.exs:73: JSONAPITest.MyPostPlug.plug_builder_call/2
test/jsonapi_test.exs:334: (test)
Is there an assertion we could add for a similar example you had in the PR description?
I added a test to serializer_test.exs
. Does it look good?
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.
Great test addition!
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.
Thank you for this PR!
I've noticed that the detail of a resource also include pagination links, but since it's only a single resource and not a list, I wouldn't expect such links there.
I added a commit trying to fix this, but as you can see, tests fail when the connection is Here is an example of failing test:
Thank you! |
I've fixed the failing tests by replacing The unsuccessful check is due to the length of the quote block in |
I think the real issue here is the Maybe we can just ignore this specific credo warning by adding
before the quote do block and maybe address issues with view macro size in another iteration. |
I've temporary suppressed the warning as suggested by @lucacorti. |
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.
LGTM. I wouldn't mind a few more eyes on this before merge.
The self url includes query parameters.
For example, the self url for
http://localhost/users?page[page]=2
is the url itself, instead ofhttp://localhost/users