在 GraphQL 中创建另一个对象时如何引用一个对象?

发布于 2025-01-10 22:28:31 字数 733 浏览 0 评论 0原文

我一直在尝试构建一个应用程序,为了简洁起见,假设我只有两种类型的对象,具有以下字段:

  1. User: user_uid, name, Settings(reference)
  2. Settings: settings_uid, some_settings_json

到目前为止,我已经尝试创建首先Settings对象,然后将准备好的Settings对象链接到正在创建的User对象。

创建设置对象:

mutation createSettings {
  createSettings(data: {some_settings_json: "{"some_key": "some_value"}" }) {
    settings_uid
  }
}

创建用户对象:

mutation createUser {
  createUser(data: {name: "some_user", settings: <SETTINGS_OBJECT>) {
    user_uid
  }
}

虽然我已经检查过文档、教程、网络;我一直无法弄清楚如何替换 ,以便这两个对象能够链接起来。注意:我不想在创建用户时创建设置。为此,教程已经提供了一个示例。

任何帮助将不胜感激。

I've been trying to build an app and for brevity, assuming that I only have two types of objects with the following fields:

  1. User: user_uid, name, Settings(reference)
  2. Settings: settings_uid, some_settings_json

So far, I've tried creating Settings object first then linking the ready Settings object to the User object getting created.

Creating the settings object:

mutation createSettings {
  createSettings(data: {some_settings_json: "{"some_key": "some_value"}" }) {
    settings_uid
  }
}

Creating the User object:

mutation createUser {
  createUser(data: {name: "some_user", settings: <SETTINGS_OBJECT>) {
    user_uid
  }
}

Although I've checked documentations, tutorials, web; I haven't been able to figure out how to replace <SETTINGS_OBJECT>, so that these two objects would get linked. Note: I don't want to create settings while user is getting created. For that, a tutorial already provides an example.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福不弃 2025-01-17 22:28:31

我找到了。该链接是通过 connect 关键字提供的。

mutation createUser {
  createUser(data: {
    name: "some_name", settings: {
      connect: {
        settings_uid: "settings_uid"
      }
    }
  }) {
    user_uid
  }
}

I found it. The link is provided via connect keyword.

mutation createUser {
  createUser(data: {
    name: "some_name", settings: {
      connect: {
        settings_uid: "settings_uid"
      }
    }
  }) {
    user_uid
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文