-
Notifications
You must be signed in to change notification settings - Fork 85
Resolves #263 added a means to disable attaching relationship metadata on unresolved includes #264
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
base: master
Are you sure you want to change the base?
Conversation
…p metadata on unresolved includes
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.
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.
| expect(product.type).to.eql('products') | ||
| expect(product.title).to.eql('hello') | ||
| expect(product.tags).to.be.an('array') | ||
| expect(product.tags).to.be.empty() |
Copilot
AI
Dec 2, 2025
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.
The assertion to.be.empty() is not a valid expect.js method. Based on the testing patterns used elsewhere in this codebase (e.g., line 180 in serialize-test.js), use .length to check array emptiness instead: expect(product.tags.length).to.eql(0) or expect(product.tags.length).to.be(0).
| expect(product.tags).to.be.empty() | |
| expect(product.tags.length).to.be(0) |
README.md
Outdated
| // => data.comment will be populated with any comments included by your API | ||
| ``` | ||
|
|
||
| By default, Devour will include relationship metadata (id, type, and other metadata) in each response. It may be handy to exclude this metadata from the response when the relationship is not resolved by the backend (not listed in the "includes" Json:api response). For this, make sure the `attachRelationshipDataOnUnresolvedIncludes` client flag is set to `false`, (default value is `true`). |
Copilot
AI
Dec 2, 2025
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.
[nitpick] The documentation sentence is awkwardly worded. Consider revising for clarity: "By default, Devour includes relationship metadata (id, type, and other metadata) for all relationships in each response. To exclude this metadata when a relationship is not resolved by the backend (i.e., not listed in the "included" section of the JSON:API response), set the attachRelationshipDataOnUnresolvedIncludes client flag to false (default value is true)."
| By default, Devour will include relationship metadata (id, type, and other metadata) in each response. It may be handy to exclude this metadata from the response when the relationship is not resolved by the backend (not listed in the "includes" Json:api response). For this, make sure the `attachRelationshipDataOnUnresolvedIncludes` client flag is set to `false`, (default value is `true`). | |
| By default, Devour includes relationship metadata (such as `id`, `type`, and other fields) for all relationships in each response. To exclude this metadata when a relationship is not resolved by the backend (i.e., not listed in the `"included"` section of the JSON:API response), set the `attachRelationshipDataOnUnresolvedIncludes` client flag to `false`. The default value is `true`. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.