Skip to content

Documentation / @ember-data/json-api / request / serializePatch

Function: serializePatch()

ts
function serializePatch(cache, identifier): object;

Defined in: warp-drive-packages/utilities/declarations/-private/json-api/serialize.d.ts:67

⚠️ This util often won't produce the necessary body for a {json:api} request

While this may come as a surprise, they are intended to serialize cache state for more generalized usage. {json:api} has a large variance in acceptable shapes, and only your app can ensure that the body is correctly formatted and contains all necessary data.

Serializes changes to a resource. Useful for use with building bodies for PATCH requests.

Only attributes which are changed are serialized. Only relationships which are changed are serialized.

Collection relationships serialize the collection as a whole.

If you would like to serialize updates to a collection more granularly (for instance, as operations) request the diff from the store and serialize as desired:

ts
const relationshipDiffMap = cache.changedRelationships(identifier);

Parameters

cache

Cache

identifier

ResourceKey

Returns

object

An object with a data property containing the serialized resource patch

data

ts
data: JsonApiResourcePatch;

Released under the MIT License.