IO-1132 improve caching after insert.

This commit is contained in:
Patrick Fic
2021-06-01 11:11:49 -07:00
parent 659881e012
commit 642568bc01
6 changed files with 49 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ import { client } from "../graphql/client";
import { INSERT_NEW_DOCUMENT } from "../graphql/documents.queries";
import { axiosAuthInterceptorId } from "./CleanAxios";
import * as MediaLibrary from "expo-media-library";
import { gql } from "@apollo/client";
//Context: currentUserEmail, bodyshop, jobid, invoiceid
@@ -143,6 +144,30 @@ export const uploadToCloudinary = async (
//Insert the document with the matching key.
const documentInsert = await client.mutate({
mutation: INSERT_NEW_DOCUMENT,
update: (cache, { data }) => {
cache.modify({
fields: {
documents: (existingDocs = []) => {
const newDocRef = cache.writeFragment({
data: data.insert_documents.returning[0],
fragment: gql`
fragment newDoc on documents {
id
name
key
type
takenat
extension
jobid
}
`,
});
return [...existingDocs, newDocRef];
},
},
});
},
variables: {
docInput: [
{