【问题标题】:Graphql relay array fieldGraphql 继电器数组字段
【发布时间】:2017-04-15 07:52:14
【问题描述】:

我开始为来自 Apollo 的中继进行开发。 我有一个在 SQLITE3 数据库上运行的哑服务器,只是为了在重构时进行测试。 在后台使用graphql-relay

目前我有这样的事情:

{
  root: {
    allFoo: [FooType]
  } 
}

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

【问题讨论】:

    标签: graphql relayjs mutation


    【解决方案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',
        },
      }];
    }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-15
      • 2020-04-04
      • 2020-10-07
      • 2021-07-26
      • 2020-08-26
      • 2020-09-27
      • 2019-10-19
      • 2023-03-31
      相关资源
      最近更新 更多