Skip to content

Commit

Permalink
fix(client): add new tag reference directly to query cache, fixes #221
Browse files Browse the repository at this point in the history
  • Loading branch information
neopostmodern committed May 20, 2023
1 parent c21b71e commit d6a8538
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions client/src/renderer/components/AddTagForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,24 @@ const AddTagForm = ({
}
const { addTagByNameToNote } = data;

const newTags = addTagByNameToNote.tags.filter((tag) =>
cache.readFragment({
id: cache.identify(tag),
fragment: BASE_TAG_FRAGMENT,
})
);
cache.modify({
id: 'ROOT_QUERY',
fields: {
tags(
existingTagsRefs: Array<{ __ref: string }> = []
): Array<{ __ref: string }> {
const newTags = addTagByNameToNote.tags
.filter((tag) => {
const tagCacheId = cache.identify(tag);

newTags.forEach((tag) => {
cache.writeFragment({
id: cache.identify(tag),
fragment: BASE_TAG_FRAGMENT,
data: tag,
});
return !existingTagsRefs.some(
({ __ref }) => __ref === tagCacheId
);
})
.map((tag) => ({ __ref: cache.identify(tag)! }));
return [...existingTagsRefs, ...newTags];
},
},
});
},
});
Expand Down

0 comments on commit d6a8538

Please sign in to comment.