Graphql中继数组字段

时间:2016-11-30 20:36:37

标签: graphql relayjs mutation

我开始开发来自阿波罗的接力赛。 我在SQLITE3数据库上运行一个愚蠢的服务器,只是为了测试而我正在重构。 在背后使用graphql-relay

目前我有这样的事情:

{
  root: {
    allFoo: [FooType]
  } 
}

我想知道如何将新的FooType项添加到allFoo列表中。 在getConfigs RANGE_ADD仅对连接起作用。 那么我需要使我的allFoo类型成为连接而不是GraphqlList(FooType)吗?或者我能以某种方式使用FIELD_CHANGE吗?

1 个答案:

答案 0 :(得分:1)

看看这个例子: https://github.com/bfwg/relay-gallery/blob/master/frontend/src/app/mutation/AddImageMutation.js#L47

以下示例是关于如何将图像添加到图像列表的演示。

getConfigs() {
  return [{
    type: 'RANGE_ADD',
    parentName: 'User',
    parentID: this.props.images.id,
    connectionName: 'images',
    edgeName: 'newImageEdge',
    rangeBehaviors: {
      '': 'prepend',
    },
  }];
}

希望这有帮助!