Skip to content

Sanity client: updating a field on an object #131

@fostimus

Description

@fostimus

Is your feature request related to a problem? Please describe.
I'm using sanity client to update one field on an object. The only way to update the object is via client.patch('id').set(fieldName: value}), but when value is an object, it overwrites the entire object on the document. Only the field specified would be nice.

Describe the solution you'd like
If an object field is set in the client, only update the fields specified in the object. Don't overwrite the entire object.

Additional context
I'd get by if I had access to the publish action's draft, so I could use the spread operator to create the correct object. Something like:

  1. get the most recent draft of the document
  2. Use the client to patch the document like: client.patch('id').set(article: { ...article, publishDate: <new date> })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions