2017-09-15 7 views
1

私は、新しいアイテムを追加するためのコレクションと突然変異を持っています。私は成功した突然変異の後にUIを更新するためにRelay Modernを得ることができませんでした。Relay Modern Mutations、RANGE_ADD/Append

私が正しくフェッチ以下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 
      } 
      } 
     } 
    ` 
    }, 

プロップとPaginationContainerセットアップを持っています。私はこのリストに連絡先を追加する突然変異を得た。 config RANGE_ADDまたはupdater:コールバックテクニックはまったく機能しません。

私はそう

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) 
     // } 
    }, 
); 
} 

答えて

0

まあ、私は

@connection(key: "ContactsList_contacts", filters: [])

にライン

@connection(key: "ContactsList_contacts")

を変更することでこの問題を解決することができた、それはそれ以外の場合は、接続を見つけることができなかったようです...

https://facebook.github.io/relay/docs/pagination-container.html#connection-directive

updater機能を使用すると、接続が見つかりました。

関連する問題