Skip to content

Commit

Permalink
update cache when pdf is added
Browse files Browse the repository at this point in the history
  • Loading branch information
bnchdrff committed May 5, 2021
1 parent 6a879d5 commit 4483546
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/containers/ManagePdfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,32 @@ const ADD_PDF = gql`
}
`;

const ADD_PDF_OPTS = {
update(cache, { data: { addPdf } }) {
cache.modify({
fields: {
pdfs(existingPdfs = []) {
const newPdfRef = cache.writeFragment({
data: addPdf,
fragment: gql`
fragment NewPdf on Pdf {
id
type
}
`,
});
return [...existingPdfs, newPdfRef];
},
},
});
},
};

const ManagePdfs = () => {
const [
addPdf,
{ loading: addPdfLoading, error: addPdfError, data: addPdfData },
] = useMutation(ADD_PDF);
] = useMutation(ADD_PDF, ADD_PDF_OPTS);

if (addPdfError) {
console.log(
Expand Down

0 comments on commit 4483546

Please sign in to comment.