feat: Add JSON:API sparse fieldset relationship support#410
Open
mattpolzin wants to merge 1 commit intomainfrom
Open
feat: Add JSON:API sparse fieldset relationship support#410mattpolzin wants to merge 1 commit intomainfrom
mattpolzin wants to merge 1 commit intomainfrom
Conversation
653ffc3 to
1f36812
Compare
The JSON:API specification allows for sparse fieldsets to limit both attribute and relationship serialization. Until now, this library only appliled sparse fieldset handling to attributes. This adds relationship support.
1f36812 to
c87faa1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #408.
The JSON:API specification allows for sparse fieldsets to limit both attribute and relationship serialization. Until now, this library only appliled sparse fieldset handling to attributes.
This adds relationship support.
Adding this support is a bit fiddly given this library already treats "fields" as a synonym for "attributes" in more than a couple of places. In order to not rip the carpet up, I chose to make this a mostly non-breaking change. I say mostly because there is still one important catch: If an existing API assumes the non-standard behavior of only filtering attributes by the sparse fieldset query parameter, then clients may request a fieldset not including relationship values that they expect to have serialized and this PR will break those API requests (which must now specify the relationship names in the sparse fieldset query parameter going forward).
Still, I consider this a bug fix given the specification is very clear about how sparse fieldsets work. Hopefully no one sees regressions in their own APIs due to this behavioral change.