简体   繁体   English

嵌套片段数据在Relay中始终相同

[英]Nested fragment data always the same in Relay

I'm new to Relay and am having an issue with nested data on a fragment. 我是Relay的新手,并且在片段上存在嵌套数据的问题。

The following query returns the correct data when I test in it graphiql so I am confident my schema is correct. 当我在graphiql中测试时,以下查询返回正确的数据,因此我确信我的架构是正确的。

 {
  viewer {
    customers {
      name
      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. 但是,当我将上述查询与Relay一起使用时, customer.name将是正确的,但customer.billing_address.city对于每个客户都是相同的。 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. 下面是我项目中目前唯一的Relay代码,我认为这个问题可能存在。

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')
);

One possible problem could by how you resolve billing_address in your GraphQL schema. 您可以通过如何解决GraphQL架构中的billing_address来解决一个问题。 Did you include an field :id, !types.ID or globalIdField in your billing_address GraphQL type? 您是否在billing_address GraphQL类型中包含field :id, !types.IDglobalIdField Posting your GraphQL schema may also help. 发布GraphQL架构也可能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM