orbitjs / orbit

Composable data framework for ambitious web applications.
https://orbitjs.com
MIT License
2.33k stars 134 forks source link

[JSON:API Atomic Operations] Support lid #948

Open SafaAlfulaij opened 2 years ago

SafaAlfulaij commented 2 years ago

When dealing with atomic operations, updating local records (added in the operation) requires the lid for the backend to understand what to update.

https://github.com/orbitjs/orbit/blob/ea8f97c92d7ee5419910f5752f12c7401a5449e2/packages/%40orbit/jsonapi/src/serializers/jsonapi-resource-identity-serializer.ts#L92-L94

The fix is as simple as this:

 if (resourceId !== undefined) {
   resource.id = resourceId;
 } else {
   resource.lid = id
}

But needs a bit of testing and checking if JSON:API allows having lid for all requests (atomic and non-atomic) or not.