Skip to content

Add relationshipsOnly to select relationship routes (#13) - #14

Merged
evoactivity merged 1 commit into
mainfrom
feat/13-relationship-route-only
Aug 12, 2026
Merged

Add relationshipsOnly to select relationship routes (#13)#14
evoactivity merged 1 commit into
mainfrom
feat/13-relationship-route-only

Conversation

@evoactivity

Copy link
Copy Markdown
Owner

What

jsonApiResource could already subset resource routes with only, but relationship routes registered all-or-nothing based on whether a relationships controller was passed. This adds a separate relationshipsOnly option that lists which relationship actions to register.

router.jsonApiResource('teams', {
  resource: () => import('#controllers/teams_controller'),
  relationships: () => import('#controllers/team_relationships_controller'),
}, { relationshipsOnly: ['show', 'related'] })

Design

Two independent lists rather than one flat list:

  • only selects resource routes: index, store, show, update, destroy.
  • relationshipsOnly selects 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 only keeps 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: new relationshipsOnly option and RelationshipActions type; split the route filter into resource and relationship checks.
  • tests/unit/register_resource.spec.ts: new spec driving registerJsonApiResource with 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

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
@evoactivity
evoactivity merged commit d1061d4 into main Aug 12, 2026
2 checks passed
@evoactivity evoactivity added the enhancement New feature or request label Aug 12, 2026
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minor - Feature Request - jsonApiResource provide a mechanism to pre-select a subset of relationship routes

1 participant