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:
@@ -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],
|
||||||
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user