Last active
October 17, 2019 09:12
-
-
Save kamilkisiela/4cae5d60691d368b94ad746be8c5b2bc to your computer and use it in GitHub Desktop.
apollo-toolkit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Before | |
this.addTransactionGQL.mutate( | |
{ input }, | |
{ | |
update: (cache, result) => { | |
const data = cache.readQuery<GetTransactions.Query>({ | |
query: GET_TRANSACTIONS_QUERY | |
}); | |
cache.writeQuery<GetTransactions.Query>({ | |
query: GET_TRANSACTIONS_QUERY, | |
data: { | |
...data, | |
transactions: [result.data.addTransaction, ...data.transactions] | |
} | |
}) | |
}, | |
}, | |
); | |
// After | |
import { update } from 'apollo-toolkit'; | |
this.addTransactionGQL.mutate( | |
{ input }, | |
{ | |
update: update((cache, result) => { | |
cache.patchQuery<GetTransactions.Query>( | |
{ | |
query: GET_TRANSACTIONS_QUERY, | |
}, | |
data => { | |
data.transactions.unshift(result.data.addTransaction); | |
}, | |
); | |
}), | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment