2017-03-01 31 views
1

我下面一個繼電器的教程,我感到困惑與這部分代碼:我很困惑Relay.QL片段,中繼的查詢和路由?

exports.Container = Relay.createContainer(ConferenceApp, { 

/* 1st id on mock database */ 
    initialVariables: { 
    userToShow: 1 
    }, 
    fragments: { 
    user:() => Relay.QL` 
/* what is this fragment on 'User'? does this has to be the name on/from the UserType Schema or this could be anything? */ 
     fragment on User { 
     name, 
     conferences(userToShow: $userToShow) { 
      edges { 
      node { 
       id, 
       name, 
       description 
      }, 
      }, 
     }, 
     } 
    ` 
    }, 
}); 

exports.queries = { 
    name: 'ConferenceQueries', 
    params: {}, // what is params purpose here? 
    queries: { 
    user:() => Relay.QL`query { user }` // why do we have this user query when we have the query above?, what is this user field? 
    }, 
} 

而且對應用程序的根,我在文檔閱讀,我只是需要有很強的把握,我我有這個OCD

<Relay.RootContainer 
    Component={ConferenceApp.Container} 
    route={ConferenceApp.queries} // is this something like react router? :/ 
    onReadyStateChange={({error}) => { if (error) console.error(error) }} /> 

我把我的問題的意見,特別指出。真的很感謝那些部分的解釋,謝謝。

回答

0

好的。讓我試着回答你。

1.「User」上的這個片段是什麼?

那麼,在GraphQL中,查詢聲明存在於根查詢類型中的字段。另一方面,GraphQL片段聲明任何類型的字段。例如,以下片段爲某個用戶提取名稱和會議。

2.什麼是params目的在這裏?

獲取您自己的示例。如果您需要獲取某個特定用戶,則需要指定用戶的ID才能獲取該用戶。所以,這就是爲什麼我們有這些參數。