Skip to main content

Posts

Showing posts with the label mutation

mutation - updateCache

  const updateCache : MutationUpdaterFn < any > = ( cache , { data }) => { const existingData : any = cache . readQuery ({ query : QUERY_ORDERS , variables : { id : listingId }, }) console . log ( existingData ) const newOrder = data . chargeCustomer console . log ( newOrder ) cache . writeQuery ({ query : QUERY_ORDERS , variables : { id : listingId }, data : { getOrders : [ newOrder , ... existingData . getOrders ] }, }) } const [ chargeCustomer ] = useMutation ( CHARGE_CUSTOMER , { update : updateCache }) function useMlsNumber ( listingId : string ): [ renderMlsNumber : any , hasMlsNumberPermission : boolean , loading : boolean ] { const classes = useStyles () const { currentAccount } = useContext ( AccountContext ) const [ open , setOpen ] = React . useState ( false ) const [ mlsNumber , setMlsNumber ] = useState ( '' ) const updateCache : MutationUpdaterFn < any...

turn GraphQL mutation into promise - with parameters

export interface SigningProps { forms : Document [] todos ?: Document [] listingId : string listingAddress : Address addDocument ?: ( data : DocumentInput ) => void printPdf ?: ( data : PrintPdfInput ) => void fillInPdfForm : ( data : FillInPdfInput ) => Promise < string > deleteTodo ?: ( id : string ) => void }   function fillInPdfForm ( fillInPdfInput : FillInPdfInput ): Promise < string > { return new Promise (( resolve , reject ) => { fillInPdf ({ variables : { fillInPdfInput : fillInPdfInput , }, }) . then (( data : any ) => { const doc = { ... data . data . fillInPdf , created : new Date (). toString (), } setDocuments ([... documents , doc ]) const todoDocs = todoDocuments . filter ( todo => todo . name !== doc . name ) setTodoDocuments ( todoDocs ) resolve ( '' ) ...