【发布时间】:2017-05-13 05:32:04
【问题描述】:
我想在组件中做这样的事情:
Relay.createContainer(Component, {
fragments: {
thing: AnotherComponent.getFragment('thing')
}
}
这将理想地设置我当前组件上的片段thing 以在其子组件之一上使用片段thing。有效地将了解thing 的责任委托给任何使用它的人。然后包含Component 的组件可以调用Component.getFragment('thing'),后者将调用AnotherComponent.getFragment('thing')。
有人知道怎么做吗?
更新
我发现完成这项工作的唯一方法是通过像
这样的语法Relay.createContainer(Component, {
fragments: {
thing: Relay.QL`
${AnotherComponent.getFragment('thing')}
`
}
}
这会正确命中服务端,服务端执行AnotherComponent指定的查询,但是现在Component的props中没有提供查询的返回值
我发现这种类型的重复嵌套会产生如下查询:
query Router {
store {
...F3
}
}
fragment F0 on Store {
_fields2w4En2:fields(labels:["Country","Function"],owner_type:"requisitions") {
choices {
id,
label
},
id
,
label
}
}
fragment F1 on Store {
...F0
}
fragment F2 on Store {
...F1
}
fragment F3 on Store {
...F2
}
在基层我有这样的查询:
export default Relay.createContainer(SearchBar, {
fragments: {
searchFields: () => Relay.QL`
fragment searchFields on Store {
searchFields: fields(labels: ["Country", "Function"], owner_type: "requisitions") {
label
choices {
id
label
}
}
}
`,
},
});
【问题讨论】: