4
定义中继容器的片段时,我们可以有条件地包含或跳过字段。 For example,如果showComments
变量为true
,则以下代码仅包含comments
。中继:有条件地包含突变胖查询中的字段
Relay.createContainer(Story, {
initialVariables: {
numCommentsToShow: 10,
showComments: false,
},
fragments: {
story: (variables) => Relay.QL`
fragment on Story {
comments(first: $numCommentsToShow) @include(if: $showComments) {
edges {
node {
author { name },
id,
text,
},
},
},
}
`,
}
});
我们怎么能有条件地包括在mutation's fat query领域?
的使用用途:而不必单独muttaions更新型的各个领域,我们可以重复使用相同的突变更新任何领域,响应只获取该字段。这样做可以使我们减少有效负载。
这个问题的动机是另一个问题Reusing a Mutation in Relay。
有趣!但是,它似乎总是不起作用(ref:https://github.com/facebook/relay/issues/1046#issuecomment-241073226)。 –