【问题标题】:Relay RANGE_ADD queryConfig on SearchType在 SearchType 上中继 RANGE_ADD queryConfig
【发布时间】:2017-08-04 23:11:53
【问题描述】:

如果新项目的parent 类似于没有ID 属性的SearchType,我试图了解应该为RANGE_ADD 突变使用什么配置。 在这种情况下应该使用什么作为parentId 或者应该如何配置这个突变?如果我不指定parentID,那么新创建的项目将不会添加到中继存储中。

我在 Relay repo 中阅读了很多问题,但我仍然不清楚如何正确处理这种突变。

【问题讨论】:

    标签: javascript graphql relayjs


    【解决方案1】:

    在您的情况下,使用静态 ID 创建 SearchType 对象会起作用。这是一个使用 graphql-ruby 的示例,但该概念应该适用于任何实现:

    https://github.com/gauravtiwari/relay-rails-blog/blob/8b257c3d32b7ef9d1aab4420257d8b6471006d0a/app/models/viewer.rb

    客户端实现如下所示:

    class SearchPostMutation extends Relay.Mutation {
      getMutation() {
        return Relay.QL`mutation {searchPosts}`;
      }
    
      getVariables() {
        return {
          // For debug, you can hard code your SearchType object's id here. 
          id: 'SA9bdDbpc4QtwzppZD0+IbJsE4QgzQ==',
        };
      }
    
      getConfigs() {
        return [{
          type: 'RANGE_ADD',
          parentName: 'searchPost',
          // For debug, you can hard code your SearchType object's id here. 
          parentID: 'SA9bdDbpc4QtwzppZD0+IbJsE4QgzQ==',
          connectionName: 'posts',
          edgeName: 'newPostEdge',
          rangeBehaviors: {
            '': 'prepend',
          },
        }];
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-24
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      • 2017-04-16
      • 2017-06-13
      • 1970-01-01
      • 2016-09-17
      相关资源
      最近更新 更多