Handle cache update when creating new global metadata

Can't be handled exactly the same way as the other meta fields
This commit is contained in:
schroda
2024-09-22 03:04:03 +02:00
parent a06e170d78
commit 9ec0e1869d

View File

@@ -1108,15 +1108,32 @@ export class RequestManager {
}, },
update(cache, { data }) { update(cache, { data }) {
cache.modify({ cache.modify({
id: cache.identify({ __typename: 'GlobalMetaType', key }),
fields: { fields: {
meta(existingMetas, { readField }) { metas(existingMetas, { readField }) {
return updateMetadata(key, existingMetas, readField, () => if (!existingMetas) {
cache.writeFragment({ return existingMetas;
data: data!.setGlobalMeta!.meta, }
fragment: GLOBAL_METADATA,
}), if (!data?.setGlobalMeta) {
return existingMetas;
}
const exists = existingMetas.nodes.some(
(meta: Reference) => readField('key', meta) === key,
); );
if (exists) {
return existingMetas;
}
const newMetaRef = cache.writeFragment({
data: data!.setGlobalMeta.meta,
fragment: GLOBAL_METADATA,
});
return {
...existingMetas,
nodes: [...existingMetas.nodes, newMetaRef],
};
}, },
}, },
}); });