1

我尝试在一个组件上进行一个addColumn和一个removeColumn突变。Chart

但是当我打电话

Relay.Store.commitUpdate(new RemoveChartColumnMutation({
  chart: this.props.viewer.chart,
  column: this.props.viewer.chart.columns[0]
})

我收到这个错误

"Fragment \"F2\" cannot be spread here as objects of type "AddChartColumnPayload\" can never be of type \"RemoveChartColumnPayload\"."

我在这里做错了什么?

export default Relay.createContainer(Home, {
  fragments: {
    viewer: () => Relay.QL`
      fragment on User {
        chart {
          columns
          ${AddChartColumnMutation.getFragment('chart')}
          ${RemoveChartColumnMutation.getFragment('chart')}
        }
      }`
  }
});

有了这些突变

class AddChartColumnMutation extends Relay.Mutation {
  getMutation() {
    return Relay.QL`mutation {addChartColumn}`;
  }
  getVariables() {
    return {
      id: this.props.chart.id,
      key: this.props.key,
      aggregation: this.props.aggregation
    };
  }
  getFatQuery() {
    return Relay.QL`
      fragment on AddChartColumnPayload {
        chart {
          columns
        }
      }
    `;
  }
  getConfigs() {
    return [{
      type: 'FIELDS_CHANGE',
      fieldIDs: {
        chart: this.props.chart.id
      }
    }];
  }
  static fragments = {
    chart: () => Relay.QL`
      fragment on Chart {
        id
        type
      }
    `
  };
}

class RemoveChartColumnMutation extends Relay.Mutation {
  getMutation() {
    return Relay.QL`mutation {addChartColumn}`;
  }
  getVariables() {
    return {
      chartId: this.props.chart.id,
      columnId: this.props.column.id
    };
  }
  getFatQuery() {
    return Relay.QL`
      fragment on RemoveChartColumnPayload {
        chart {
          columns
        }
      }
    `;
  }
  getConfigs() {
    return [{
      type: 'FIELDS_CHANGE',
      fieldIDs: {
        chart: this.props.chart.id
      }
    }];
  }
  static fragments = {
    chart: () => Relay.QL`
      fragment on Chart {
        id
        type
      }
    `
  };
}
4

1 回答 1

2

我认为您的代码中出现了拼写错误。看起来两个突变都在调用addChartColumn突变,这可以解释预期删除图表列有效负载的错误。

于 2016-03-02T23:40:20.770 回答