Skip to content

Add SDK support for the "Detailed" create/update/delete object on relation array field - #28232

Draft
kheiner wants to merge 7 commits into
directus:mainfrom
kheiner:feat/25955-sdk-nested-crud-object
Draft

kheiner wants to merge 7 commits into
directus:mainfrom
kheiner:feat/25955-sdk-nested-crud-object

Conversation

@kheiner

@kheiner kheiner commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

What's Changed

  • Added NestedItemsInput<RawItem> to NestedPartial so that the API's "Detailed" { create, update, delete } object is supported
  • RelationPrimaryKey<Item> resolves the items id type for delete entries with a fallback to string | number
  • update entries switch id?: ... to id: ... when id is a key ⭐ 1

Tested Scenarios

  • Added coverage for createItem/createItems/updateItem/updateItems/updateItemsBatch for the NestedPartial describe blocks
  • I switched three .toEqualTypeOf() assertions to use .branded.toEqualTypeOf() since the intersection output was difficult to read. Vitest's Docs say to "This helper comes at a performance cost and can cause the TypeScript compiler to 'give up' if used with excessively deep types. Use it sparingly and only when necessary." When I checked the performance speed I found no discernible difference between branded and unbranded.
  • Played with it a bit on a live sandbox just to make sure the shapes worked (delete truly only accepts plain primary keys and not { id } objects

Review Notes / Questions / Concerns

  • ⭐ 10eaf256 is for the devs who live dangerously and don't use id for the primary key. I don't know how to protect them from themselves, so whatever they chose to be the pk is optional and up to them to pass it along.
  • The { create, update, delete } object passes for JSON. So if a dev accidentally passes the CRUD object to a field that is not relational and is typed to receive JSON, they still get a code 200 as a response. The API does the same thing, just calling it out as a new place to make a mistake you can already make in the API.
  • minor felt right but I kept switching between patch and minor in my head.
  • Issue title says "M2O and M2M" but m2o isn't supported in the API.

Checklist

Leave unchecked where not applicable

  • Tests added/updated
  • Documentation PR created in Fix Headings on Relational Data Guide docs#824 (not a content change, but the headings were wrong so it's related)
  • OpenAPI updated
  • SDK (@directus/sdk) updated to reflect the changes
  • Types (@directus/types) updated to reflect the changes
  • GraphQL schema updated to reflect the changes
  • System data (@directus/system-data) updated for changes to system collections/fields/relations
  • Database migration added for schema/system changes
  • Environment variables documented for new/changed config
  • App translations added for new user-facing strings
  • Security implications apply

Fixes #25955

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SDK] CRUD object not supported in M2O and M2M create/update

1 participant