-
Notifications
You must be signed in to change notification settings - Fork 77
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
Fully Support Sparse Fieldsets #171
Conversation
@kbaird I think this pull request will resolve your issue with spare fieldsets, but I could use a hand in testing it. Assuming you're using the 7d5cf21#diff-b3e75c65fe619484c7646cf236da6b66R281 Note that no changes to your code will be required unless you've overridden the |
@jherdman could you rebase this PR to remove the commits already in master? 😁 |
@doomspork will do! Are you up for doing the 1.0 release first? I'm unable to do releases still. |
@jherdman for sure, I'm ready whenever we've got the team consensus 👍 |
3a37e79
to
149e44f
Compare
@doomspork I've made some updates per your suggestions |
@jherdman I'm also trying to test and having some issues. with
Any thoughts? |
A little while back we moved around some plugs and changed the name of that one to |
@jherdman I'm also getting quite a few dialyzer errors now. FYI. |
And
Basic GET index with filtering |
Ah, drat! Would you mind pasting your dialyzer errors into here too?
This is a 1.0 change. My apologies for the bumps in the road, we're definitely doing the testing of this ticket the hard way 😁 . You'll need to configure how your fields are transformed. See: https://github.com/jeregrine/jsonapi#configuration |
The payload worked with jsonapi 0.8. Here's a typical dialyzer error:
|
@kbaird I'm having trouble tracking down that Dialyzer error. I have a few ideas though:
My hunch is that you'll still see the Dialyzer errors. Would you mind reporting them? I think it'll help focus the remainder of this ticket. |
@jherdman Will do. It might be Monday or Tuesday. Thanks. |
lib/jsonapi/view.ex
Outdated
### Advanced Fields Usage | ||
|
||
Note that the overriddable `attributes/2` method can be used for more control | ||
over which fields are serialized from your view. It is **strongly** recommended |
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.
@doomspork @snewcomer I've added some documentation here about using visible_fields/2
, and a bit of eager documentation about attributes/2
being deprecated at some point. Frankly I think we ought to tighten the screws on View
a tad, so this may be a bit presumptuous of me. I can peel back this warning if you disagree.
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.
Sounds good. Not sure if it is worthwhile adding why attributes
may be deprecated (just for posterity sake)
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.
Good point! I'll beef up the new note a bit.
@snewcomer @doomspork back at ya! |
Sounds great, @kbaird ! Many thanks for your time and help. |
So we were able to upgrade successfully, with the one note that when you do not specify "type" in a create or update action, the error message is incorrect. It said /data/attributes was the issue when it was actually /data/type. |
Hmm... It should have "just worked". Are you able to share your view code? |
Tried again after the force push. Same failures. |
@kbaird you're too fast ;) I think I know what's going on, but I found another bug in the process of digging into your issue. Hopefully I'll resolve your issue soon. |
try do | ||
value | ||
|> String.split(",") | ||
|> Enum.map(&underscore/1) |
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 think this could be considered a bug insofar that UnderscoreParameters
doesn't catch this.
I used |
No worries! Does that mean everything is working for you now?
…On Tue, Feb 12, 2019 at 22:08 Kevin C. Baird ***@***.***> wrote:
I used commit: rather than branch:. Sorry, user error on my part.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#171 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAM5A_amfAASFi10YJGElNJulv7U4qWks5vM4G9gaJpZM4ac5t8>
.
|
Sorry, I misread your last message. That's great news! Many thanks for helping. I'll be sure to cut a release soon for you. @doomspork I think we're good to go on this. Any last concerns before I merge this? |
lib/jsonapi/view.ex
Outdated
### Advanced Fields Usage | ||
|
||
Note that the overriddable `attributes/2` method can be used for more control | ||
over which fields are serialized from your view. It is **strongly** recommended |
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.
Sounds good. Not sure if it is worthwhile adding why attributes
may be deprecated (just for posterity sake)
295905c
to
ae621db
Compare
@snewcomer I decided to pull the note on deprecating |
@doomspork @snewcomer should be ready for another round of reviewing. |
@doomspork @snewcomer any concerns with merging this? |
Yeah, pretty much. I kind of like that name. I'll make a change shortly.
…On Sun., Feb. 17, 2019, 13:26 Scott Newcomer ***@***.*** wrote:
***@***.**** commented on this pull request.
------------------------------
In lib/jsonapi/view.ex
<#171 (comment)>:
> + defp fields_for_type(requested_fields, fields) when requested_fields in [nil, %{}],
+ do: fields
+
+ defp fields_for_type(requested_fields, fields) do
+ fields
+ |> MapSet.new()
+ |> MapSet.intersection(MapSet.new(requested_fields))
+ |> MapSet.to_list()
+ end
+
+ @SPEC visible_fields(map(), conn :: nil | Conn.t()) :: list(atom)
+ def visible_fields(data, conn) do
+ all_fields =
+ conn
+ |> requested_fields_for_type()
+ |> fields_for_type(fields())
Is this something like "net fields for type"? Just trying to think of a
different name if you also agreed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#171 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAM5A6rDIFb0ZSLZQ7TZr7wVQUHLGWsks5vOZ7SgaJpZM4ac5t8>
.
|
@snewcomer — renamed as requested. |
"first_character" => "H" | ||
} == attributes | ||
end | ||
end |
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.
Last question and I swear I'm done. Is there a proper test where say excerpt
is not included in the response b/c it wasn't in the fields map?
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.
There is now 😄
Whilst the `QueryParser` was correctly identifying requested fieldsets, nothing was done to actually support this. This change prunes returned fields to those requested should it be the case. Note that this change also includes a few more typespecs for functions I touched or read. Resolves beam-community#120 Closes beam-community#156
|
||
def hidden(_data) do | ||
[:email] # will be removed from the response | ||
end |
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.
One thing that has stumped me so far is the need for this as a public API. Since it seems one would just modify fields
to not include email
. Is there a reason to have this as a public API you think?
(btw I am so sorry for going back and forth. I should have gotten these comments all rolled up into one review :()
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.
hidden/1
comes from #126. The gist seems to be conditionally excluding fields given the data available. I think an example scenario is hiding a sensitive field from users with lower privilege.
Anyways, given that it's been part of the public API for a while we ought to leave it as such.
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.
Oh you are right.
In the past, for lower privileges, I take advantage of checking the logic in a function for that specific field. But perhaps this allows bulk sending in fields to hide.
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.
Documenting as such still seems weird but since it has been there 👍
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.
🎈 🎉
@doomspork can I get an amen? |
Whilst the
QueryParser
was correctly identifying requested fieldsets,nothing was done to actually support this.
This change prunes returned fields to those requested should it be the
case.
Note that this change also includes a few more typespecs for functions I
touched or read.
Resolves #120
Closes #156