我是 GraphQL 和 Relay 的新手,我正在努力处理查询、片段、...传播和传递道具。我认为我不必要地通过许多组件传递道具。我想学习如何将我的数据对象从 QueryRenderer 传送到深度嵌套的组件,跳过所有祖先组件。
假设我有这样的组件结构。EmojisList
我需要应用程序深处的组件内的“表情符号”表中的表情符号列表。我不确定在哪里传播或传递道具,或者何时询问实际的标量。
<MainApp>
<QueryRenderer
environment={environment}
query={graphql`
query MainAppQuery {
currentPerson { // current user
...Timeline_currentPerson
}
allEmojis {
...ReactionBar_emojisList
}
}
`}
/>
<Timeline currentPerson={props.currentPerson}>
<PostList>
<Post>
<ReactionBar>
<EmojisList>
// I need this list
export default createFragmentContainer(ReactionBar, {
emojisList: graphql`
fragment ReactionBar_emojisList on EmojisConnection @relay(plural: true) {
edges {
node {
name
rowId
}
}
}
`,
});
</EmojisList>
</ReactionBar>
</Post>
</PostList>
</Timeline>
</MainApp>