2017-10-31 6 views
0

내 쿼리에 대한 구독을 수행하려고합니다. 그래서 내 의심은 ConnectionHandler의 연결이 작동하지 않는다는 것입니다. 이 문서에 대한 적절한 문서를 찾을 수 없습니다. 당신은 코드에서 볼 수있는 바와 같이Relay Modern - Subscription updater (연결 처리기) 방법 (이 문제에 대한 문서 없음)

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

난 내가 뭘 잘못했는지 볼 수있는 로그를 많이 실행 :

내 구독 것 같습니다. 특정 ID 등재 일자 (59f88d417fae441eb567c453)에 대한 RelayRecordProxy //

로그 DEBUG3 화재 :

로그 DEBUG 화재 : RelayRecordSourceSelectorProxy,

로그 DEBUG2 화재 RelayRecordProxy // 클라이언트 : 루트,

로그인 DEBUG4 화재 : RelayRecordProxy // 클라이언트 : 루트 : 59f88d417fae441eb567c453,

로그 DEBUG5 : undefined,

01 23,516,

로그인 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 : 릴레이 모던 구독은 가장자리/뷰어없이 작동합니까? Question3 : 누구나 console.log를 'connectionHandler.getConnection'에 저장할 수 있습니까? –