IO-1132 improve caching after insert.
This commit is contained in:
@@ -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: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user