中继中的嵌套片段数据始终相同 [英] Nested fragment data always the same in Relay
问题描述
我是Relay的新手,但是片段上的嵌套数据有问题.
I'm new to Relay and am having an issue with nested data on a fragment.
当我在graphiql中进行测试时,以下查询返回正确的数据,因此我确信我的架构是正确的.
The following query returns the correct data when I test in it graphiql so I am confident my schema is correct.
{
viewer {
customers {
name
billing_address {
city
}
}
}
}
但是,当我将上述查询与Relay一起使用时, customer.name
将是正确的,但是 customer.billing_address.city
对于每个客户都是相同的.这使我感到困惑,为什么在只复制嵌套数据的同时某些数据还是正确的.
However, when I use the above query with Relay the customer.name
will be correct but customer.billing_address.city
is the same for every customer. It's confusing to me why some of the data would be correct while the nested data would just be copied.
对于这个问题的任何帮助,我们将不胜感激,如果需要更多信息,我将很高兴添加它.以下是我的项目中目前存在的唯一中继代码,我认为可能是该问题所在.
I would appreciate any help with the issue and if anymore information is needed I would be glad to add it. Below is the only Relay code currently in my project and where I believe the issue may be.
class App extends Component {
render() {
console.log(this.props.viewer.customers);
return (
<div>
{this.props.viewer.customers.map((customer) => (
<div>
<div>{customer.name}</div>
<div>{customer.billing_address.city}</div>
</div>
))}
</div>
);
}
}
class AppHomeRoute extends Relay.Route {
static queries = {
viewer: () => Relay.QL`
query {
viewer
}
`,
};
static routeName = 'AppHomeRoute';
}
const AppContainer = Relay.createContainer(App, {
fragments: {
viewer: () => Relay.QL`
fragment on Viewer {
customers{
name
billing_address{
city
}
}
}`
},
});
ReactDOM.render(
<Relay.RootContainer
Component={AppContainer}
route={new AppHomeRoute()}
/>,
document.getElementById('root')
);
推荐答案
一个可能的问题可能是如何解决GraphQL模式中的billing_address.在billing_address GraphQL类型中是否包含 field:id,!types.ID
或 globalIdField
?发布您的GraphQL模式也可能会有所帮助.
One possible problem could by how you resolve billing_address in your GraphQL schema. Did you include an field :id, !types.ID
or globalIdField
in your billing_address GraphQL type? Posting your GraphQL schema may also help.
这篇关于中继中的嵌套片段数据始终相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!