首页 > 解决方案 > 如何使用 GraphQL 创建/改变一行,其中一个字段是 Realm 中的引用

问题描述

我在 Realm 中创建了以下(测试)集合:

RoundType(集合)

  uuid (string)
  name  (string)

RoundType 中的数据(1 行)

uuid: 234dfg345dfg345    name: Fred Flintstone 

测试突变(集合)

 uuid (string)
 roundType  (RoundType)

TestMutate 中的数据:还没有


我想在 TestMutate 中创建一个新行,其中 TestMutate 中的“roundType”字段是对现有RoundType 行的引用。

我尝试了以下方法,希望 GraphQL 知道 roundType 存在,但显然这是不对的。

mutation {
  result: addTestMutate(input: {uuid: "abc123", roundType: {id: "234dfg345dfg345"}}) {
        uuid   
  }
}

GraphQL 中实现此目的的正确语法是什么?

标签: realmgraphql

解决方案


很酷,我明白了。只需使用**update**TestMutate(..)而不是addTestMutate这样:

mutation {
    updateTestMutate(input: {uuid: "abc123", roundType: {id: "234dfg345dfg345"}}) {
    uuid
  }
}

推荐阅读