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 }) {
cache.modify({
id: cache.identify({ __typename: 'GlobalMetaType', key }),
fields: {
meta(existingMetas, { readField }) {
return updateMetadata(key, existingMetas, readField, () =>
cache.writeFragment({
data: data!.setGlobalMeta!.meta,
fragment: GLOBAL_METADATA,
}),
metas(existingMetas, { readField }) {
if (!existingMetas) {
return existingMetas;
}
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],
};
},
},
});