`serializeResources` brings `links` -> `related` to API on record update
I'm not 100% sure, but i think there is an incorrect implemenation of JSON-API in warp-drive with schema record..
The serializeResources helper returns the links object, which i think is not wanted and also out of JSON-API specs for PUT (and also PATCH) or?
I think the correct ways is to remove links completely from payload or?
https://github.com/emberjs/data/blob/553ab52ef12a595f54cd85bd07c362d88ce542e2/warp-drive-packages/utilities/src/-private/json-api/serialize.ts#L35-L44
Version: Ember: 6.6 EmberData: 5.6
The spec is silent on whether links may be included or not during an update/PATCH. I've err'd on the side of exposing all the information someone might want for the resource. Though I could be convinced to drop links/meta if there's consensus that is better.
do you think, there is an usecase in which the server need to know, which links were provided to client before?
links are present just when the server has retured the model, in all other cases it doesn't exists.
I think in most cases there is just the payload larger and brings info to the server, which has no effects.
Alternative could be, to make an option? What do you think about that?
It's more that the utility is meant for generic "give me what is in the cache" not "give me a payload meant for my API". And there are a ton of use cases for "give me what is in the cache" that do not involve requests against your API.
We may need to rethink some of the utilities though .. I want them to be broadly useful even when they are mostly intended to show how you could do something and not necessarily to be the thing that you do use.
@runspired is there any plan to make serializeResources more JSON:API conform?
Today (with warp-drive v5.8.0) we have in our apps this workarounds inside request manager to get JSON API conform (on server we have strict validation)
import { serializeResources } from '@warp-drive/utilities/json-api';
import type { Store } from '@warp-drive/core';
const resourceData = serializeResources((store as Store).cache, record);
if (resourceData.data.relationships) {
for (const relationshipKey of Object.keys(resourceData.data.relationships)) {
// Don't pass links to API, unnecessary payload - Issue https://github.com/warp-drive-data/warp-drive/issues/10098
if (resourceData.data.relationships[relationshipKey]?.links) {
delete resourceData.data.relationships[relationshipKey].links;
}
// Fix data.id = null relationship, This issue is when there is a 1:1 relation. but the id is not stored on main object. We need to save main element and than belongsTo relation, because id from main is required in other object)
if (resourceData.data.relationships[relationshipKey]) {
if (
!Array.isArray(resourceData.data.relationships[relationshipKey].data) &&
resourceData.data.relationships[relationshipKey].data?.id === null
) {
delete resourceData.data.relationships[relationshipKey];
}
}
}
}
// Workaround, id = null is invalid, id must be a string or not present in json api (https://jsonapi.org/format/#document-resource-objects) - Issue https://github.com/warp-drive-data/warp-drive/issues/10360
if (resourceData.data['id'] === null) {
// @ts-expect-error The operand of a 'delete' operator must be optional.
delete resourceData.data.id;
}