gpt4 book ai didi

relayjs - 继电器: Conditionally include fields in mutation's fat query

转载 作者:行者123 更新时间:2023-12-02 11:22:17 25 4
gpt4 key购买 nike

在定义 Relay 容器的片段时,我们可以有条件地包含或跳过字段。 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 中包含字段?

使用-使用:我们可以重复使用相同的突变来更新任何字段,并在响应中仅获取该字段,而不是使用单独的突变来更新类型的每个字段。这样做使我们能够减少有效负载。

这个问题是由另一个问题Reusing a Mutation in Relay引发的.

最佳答案

您实际上可以在 FatQuery 上使用字符串插值:

getFatQuery() {
return Relay.QL`
fragment on EditCommentPayload {
comment {
${this.props.fields.join(',')}
}
}
`;

这似乎有点反 GraphQL,但不幸的是,胖查询 ( related issue ) 没有变量。

关于relayjs - 继电器: Conditionally include fields in mutation's fat query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37272323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com