2017-10-31 5 views
0

私のクエリのサブスクリプションを実行しようとしています。だから私の疑念は、ConnectionHandlerからの接続が機能していないということです。私はこれに関する適切な文書を見つけることができません。あなたは私が間違って何をしたか確認するためにログをたくさん走ったコードで見ているようRelay Modern - サブスクリプションアップデータ(接続ハンドラ)メソッド(この問題に関するドキュメントはありません)

const LinkSubscription = graphql` 
    subscription LinkSubscription { 
    Link(filter:{ 
     mutation_in:[CREATED] 
    }){ 
     node{ 
     id 
     } 
    } 
    } 
`; 

export default() => { 
    const subscriptionConfig = { 
    subscription: LinkSubscription, 
    variables: {}, 
    onCompleted:() => { alert('done!'); }, 
    updater: (Store, data) => { 
     const newLink = Store.getRootField('Link').getLinkedRecord('node'); 
     const allLinks = Store.getRoot(); 
     const edge = ConnectionHandler.createEdge(Store, allLinks, newLink, 'allLinks'); 
     const userId = localStorage.getItem('user_id'); 
     const connection = ConnectionHandler.getConnection(allLinks, newLink, 'allLinks'); 
     if (connection) { 
     ConnectionHandler.insertEdgeAfter(connection, newLink); 
     console.log('DONE'); 
     } 
     console.log('DEBUG', Store); 
     console.log('DEBUG2', newLink); 
     console.log('DEBUG3', allLinks); 
     console.log('DEBUG4', edge); 
     console.log('DEBUG5', connection); 
     console.log('DEBUG6', ConnectionHandler); 
     console.log('DEBUG7', userId); 
     console.log('Debug8', data); 
    }, 
    onError: error => console.log('An error occured:', error), 
    }; 
    requestSubscription(Environment, subscriptionConfig); 
}; 

私のサブスクリプションは次のようになります。

ログDEBUG火災:RelayRecordSourceSelectorProxy

ログDEBUG2火災:特定のidのRelayRecordProxy //(59f88d417fae441eb567c453)を作成し、

ログDEBUG3火災:クライアントのRelayRecordProxy //:ルート、

ログDEBUG4火災:RelayRecordProxy //クライアントのために:ルート:59f88d417fae441eb567c453、

ログDEBUG5:undefined

ログインDEBUG6:ConnectionHandler方法、

ログDEBUG7:クエリを要求したuser.id

質問1:接続に関するいくつかの提案がありますか?

答えて

0

サブスクリプション:私はドキュメントを読んでいるUpdating the client on each response

const LinkSubscription = graphql` 
    subscription LinkSubscription { 
    Link(filter: { mutation_in: [CREATED] }) { 
     node { 
     id 
     } 
    } 
    } 
`; 

export const test =() => { 
    const subscriptionConfig = { 
    subscription: LinkSubscription, 
    variables: {}, 
    onCompleted:() => { 
     alert('done!'); 
    }, 
    updater: (Store, data) => { 
     const newLink = Store.getRootField('Link').getLinkedRecord('node'); 
     const viewerProxy = Store.getRoot().getLinkedRecord('viewer'); 

     const connection = ConnectionHandler.getConnection(
     viewerProxy, 
     '<nameConnection>', // 'Viewer_links' or <Name_links> 
     { mutation_in: ['CREATED'] } 
    ); 
     const edge = ConnectionHandler.createEdge(
     Store, 
     connection, 
     newLink, 
     'LinkEdge' 
    ); 
     if (connection) { 
     ConnectionHandler.insertEdgeBefore(connection, edge); 
     console.log('DONE'); 
     } 
    }, 
    onError: error => console.log('An error occured:', error) 
    }; 

    requestSubscription(Environment, subscriptionConfig); 
}; 
+0

が示唆されました。 'connectionHandler'に関する情報はありません。これはテストサブスクリプションだと思って、私はさらに私のアプリのための実際のスキーマを生成するために働くでしょう。上記の質問はまだ有効です。 2番目と3番目の質問2:リレーモダンの購読はエッジ/ビューアなしで機能しますか?質問3:誰かが 'connectionHandler.getConnection'でconsole.logを救うことができますか? –

関連する問題