Resolves #263 added a means to disable attaching relationship metadata on unresolved includes#264
Open
ibustosatlegalzoom wants to merge 3 commits intodevour-js:masterfrom
Open
Resolves #263 added a means to disable attaching relationship metadata on unresolved includes#264ibustosatlegalzoom wants to merge 3 commits intodevour-js:masterfrom
ibustosatlegalzoom wants to merge 3 commits intodevour-js:masterfrom
Conversation
…p metadata on unresolved includes
There was a problem hiding this comment.
Pull request overview
This PR introduces a new configuration flag attachRelationshipDataOnUnresolvedIncludes to control whether relationship metadata (id, type) should be attached to responses when the related resources are not included in the API response. The flag defaults to true for backward compatibility, but when set to false, only fully resolved (included) relationships will have their data populated.
Key changes:
- Added
attachRelationshipDataOnUnresolvedIncludesflag to the JsonApi constructor with a default value oftrue - Modified deserialize logic to conditionally attach relationship data based on the flag for both
hasOneandhasManyrelationships - Added comprehensive test coverage for both relationship types with the new flag disabled
- Updated README with documentation explaining the new feature
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/index.js | Adds the new attachRelationshipDataOnUnresolvedIncludes configuration option to the defaults and assigns it to the instance |
| src/middleware/json-api/_deserialize.js | Wraps the unresolved relationship data attachment logic in conditional checks for both attachHasOneFor and attachHasManyFor functions |
| test/api/deserialize-test.js | Adds two new test cases verifying the flag prevents relationship metadata attachment for unresolved hasMany and hasOne relationships |
| README.md | Documents the new flag and its purpose in the Relationships section |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Screenshot
N/A
What Changed & Why
Learn more at #263
Introduced a flag
attachRelationshipDataOnUnresolvedIncludeswhich by default is set to true for backwards-compatibility purposes.When set to true, Devour will continue to attach relationship metadata in the client's response on unresolved includes as it normally does.
When set to false however, Devour will abstain from attaching such metatada. This applies both for relationships of type
hasManyandhasOne-Testing
Just run the tests.
Documentation
Updated the README file with instructions.