2017-07-28 109 views
3

我有以下組件可以改變數據。 Apollo提供了自動更新商店的功能。我想通過使用update函數來控制數據添加到商店的方式。文檔很簡單,但我無法正常工作。下面的代碼有什麼問題會阻止打印console.log突變未更新的更新方法

import React from 'react' 
import { connect } from 'react-redux'; 
import { graphql, gql, compose } from 'react-apollo'; 
import { personCodeSelector } from '../../selectors/auth'; 
import UploadBankStatement from '../../components/eftFileUploads/UploadBankStatement.jsx'; 

const createEftFileUpload = gql`mutation createEftFileUpload(
    $bankAccountCode: String!, 
    $uploadInput: UploadInput!, 
    $uploadedByPersonCode: String!) { 
    createEftFileUpload(
     bankAccountCode: $bankAccountCode, 
     uploadInput: $uploadInput, 
     uploadedByPersonCode: $uploadedByPersonCode) { 
      id 
      bankAccountCode 
      fileName 
      numberOfProcessedItems 
      numberOfUnallocatedItems 
      createdAt 
      status 
     } 
     }`; 

const mutationConfig = { 
    props: ({ ownProps, mutate }) => ({ 
    createEftFileUpload: (bankAccountCode, uploadInput) => { 

     return mutate({ 
     variables: { 
      bankAccountCode, 
      uploadInput, 
      uploadedByPersonCode: ownProps.personCode 
     }, 
     update: (store, something) => { 
      console.log("ping"); 
      console.log(store, something); 
      }, 
     }); 
    } 
    }) 
}; 

const mapStateToProps = state => { 
    return { 
    personCode: personCodeSelector(state) 
    }; 
}; 

export default compose(
    connect(mapStateToProps), 
    graphql(createEftFileUpload, mutationConfig) 
)(UploadBankStatement); 

注意我已經發現了幾個類似的issues,但它似乎並沒有擺脫對我的情況任何光線。

回答

0

服務器重啓解決了我的問題。不知道爲什麼這是熱重裝所必需的。代碼是正確的。