Add relationshipsOnly to select relationship routes (#13) - #14
Merged
Conversation
jsonApiResource could subset resource routes via only but registered relationship routes all-or-nothing. Add a separate relationshipsOnly option listing the relationship actions to register (show, replace, add, remove, related). The two lists are independent: omit one and every route on that axis registers, so only keeps its current meaning and nothing breaks. Closes #13
Merged
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.
What
jsonApiResourcecould already subset resource routes withonly, but relationship routes registered all-or-nothing based on whether arelationshipscontroller was passed. This adds a separaterelationshipsOnlyoption that lists which relationship actions to register.Design
Two independent lists rather than one flat list:
onlyselects resource routes:index,store,show,update,destroy.relationshipsOnlyselects relationship routes:show,replace,add,remove,related.Each token matches its controller method name. Omit a list and every route on that axis registers, so
onlykeeps its current meaning and nothing breaks. Subsetting one axis leaves the other whole, so you do not have to enumerate every resource action just to trim relationship routes.Changes
src/routes.ts: newrelationshipsOnlyoption andRelationshipActionstype; split the route filter into resource and relationship checks.tests/unit/register_resource.spec.ts: new spec drivingregisterJsonApiResourcewith a recording fake router, covering the default set, each axis in isolation, both together, and each controller alone.docs/reference.md: new "Selecting routes" section with a token table per axis.docs/writing-data.md: pointer to the reference.Checks
134 tests pass, typecheck clean, lint clean, formatted.
Closes #13