2017-09-15 42 views
1

我有一個集合和一個向其添加新項目的變種。我無法通過Relay Modern在成功突變後更新用戶界面。Relay Modern Mutations,RANGE_ADD/Append

我有一個PaginationContainer設置有以下query:道具

{ 
    query: graphql` 
     fragment ContactsList_query on WPQuery { 
      id 
      contacts: posts(
       first: $count, 
       after: $cursor 
       post_type: $postType, 
       order: $order, 
       category_name: $categoryName 
     ) @connection(key: "ContactsList_contacts") { 
      edges { 
       node { 
       id 
       ...ContactListItem_contact 
       } 
      } 
      pageInfo { 
       hasNextPage 
       endCursor 
      } 
      } 
     } 
    ` 
    }, 

能夠正確讀取。然後,我得到了一個突變,將聯繫人添加到此列表中。 配置RANGE_ADDupdater:回調技術都不起作用。

我觸發這種突變像這樣

onSave = (fields) => { 
    insertPost(
     fields.toJS(), 
     this.props.query.id, 
     this.props.relay.environment 
    ); 
    } 

沒有錯誤,只是沒有更新。

const mutation = graphql` 
    mutation InsertPostMutation(
    $data: InsertPostInput! 
) { 
    insert_post(input: $data) { 
     wp_query { 
     id 
     } 
     postEdge { 
     node { 
      id 
      title 
     } 
     } 
    } 
    } 
`; 

export default function insertPost(data, id, environment) { 
    const variables = { 
    data, 
    }; 

    commitMutation(
    environment, 
    { 
     mutation, 
     variables, 
     onCompleted: (response, errors) => { 
     console.log('Response received from server.') 
     }, 
     onError: err => console.error(err), 
     configs: [{ 
     type: 'RANGE_ADD', 
     parentID: id, 
     connectionInfo: [{ 
      key: 'ContactsList_contacts', 
      rangeBehavior: 'append', 
     }], 
     edgeName: 'postEdge' 
     }], 
     // updater: (store) => { 
     // // const inspector = new RecordSourceInspector(store) 
     // const payload = store.getRootField('insert_post') 
     // const newEdge = payload.getLinkedRecord('postEdge') 
     // const proxy = store.get(id) 
     // // Conn is always undefined here 
     // const conn = ConnectionHandler.getConnection(proxy, 'ContactsList_contacts') 
     // ConnectionHandler.insertEdgeAfter(conn, newEdge) 
     // } 
    }, 
); 
} 

回答

相關問題