如何使用GraphQL API插入数据到Astra DB?

发布于 01-19 00:19 字数 1117 浏览 4 评论 0原文

我正在尝试跟随此YouTube tutorial

我被困在插入第一片数据上。 Ania在20.46中证明了这一点,如下所示:

mutation insertGenres {
  action: insertreference_list(value: {label: "genre", value: "action"}) {
    value{
      value
    },
  }

当我尝试此操作时,我会遇到一个错误,说:

{
  "errors": [
    {
      "message": "Validation error of type FieldUndefined: Field 'insertreference_list' in type 'Mutation' is undefined @ 'insertreference_list'",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "extensions": {
        "classification": "ValidationError"
      }
    }
  ]
}

当我搜索错误时,许多响应告诉人们使用突变而不是查询 - 但是我是从突变开始的。我想知道如何解决错误,但我也想找到提高我找到答案搜索策略的技能。

当我查看将GraphQl与DataStax一起使用的文档时,我看到了与写结构的不同格式,如下所示:

insertbook(值:bookinput!,ifnotexists:boolean,选项: 更新):BookMuntresult

它具有结肠和文字片段。它还明确说明了ifnotexists:布尔和选项。我不知道如何使用DataStax有一个更改,因为Ania记录了该教程的时间,这意味着它不再是当前有关使用该工具的当前演示,或者是否有答案,我只是还没有找到它。

I am trying to follow this youtube tutorial.

I am getting stuck at inserting the first piece of data. Ania demonstrates it at 20.46 as follows:

mutation insertGenres {
  action: insertreference_list(value: {label: "genre", value: "action"}) {
    value{
      value
    },
  }

When I try this, I get an error that says:

{
  "errors": [
    {
      "message": "Validation error of type FieldUndefined: Field 'insertreference_list' in type 'Mutation' is undefined @ 'insertreference_list'",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "extensions": {
        "classification": "ValidationError"
      }
    }
  ]
}

When I google the error, a lot of responses tell people to use mutations instead of queries - but I've started from a mutation. I would like to know how to resolve the error, but I'd also like to find the skills to improve my search strategy for finding answers.

When I look at the documentation for using GraphQL with DataStax, I see a different format to the write structure, which is as follows:

insertbook(value: bookInput!, ifNotExists: Boolean, options:
UpdateOptions): bookMutationResult

It has a colon and a fragment of text after it. It also explicitly states the ifNotExists: Boolean and options. I don't know if there may have been a change to how to use DataStax since the time Ania recorded the tutorial that means it is no longer a current demonstration of how to use the tool, or if there is an answer for this and I just haven't found it yet.

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

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

发布评论

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

评论(1

黯然2025-01-26 00:19:26

您没有提供如何为 Ania 的 Netflix 克隆 教程,所以我假设您已经命名了您的键空间为 netflix

您似乎没有正确遵循说明并错过了步骤。如果我至少跳过本教程中的一个步骤,我可以复制您报告的错误。

第 5 步在教程中,您需要执行以下操作:

✅ 在 graphQL Playground 中,将选项卡更改为现在使用 graphql。编辑 URl 的末尾,将 system 更改为您的键空间名称:netflix

✅ 使用您的令牌填充页面底部的 HTTP HEADER 变量 x-cassandra-token ,如下所示(再次!!是的,这不是同一个选项卡)

切换选项卡

为了插入数据,您需要切换到 graphql 选项卡。

如果您尝试在 graphql-schema 选项卡中插入数据,您将收到报告的错误。

设置键空间

您需要在 graphql 选项卡中更新 GraphQL Playground 的 URI,以使用键空间名称 netflix 而不是 system。例如:

https://db_id-us-west1.apps.astra.datastax.com/api/graphql/system

更改为:

https://db_id-us-west1.apps.astra.datastax.com/api/graphql/netflix

如果您尝试将数据插入到system键空间中,您将收到报告的错误,因为reference_list表在该键空间中不存在。干杯!

You didn't provide details of how you've configured your Astra DB for Ania's Netflix Clone tutorial so I'm going to assume that you've named your keyspace as netflix.

It seems as though you haven't followed the instructions correctly and have missed steps. I can replicate the error you reported if I skip at least one of the steps in the tutorial.

In step 5 of the tutorial, you needed to do the following:

✅ In graphQL playground, change tab to now use graphql. Edit the end of the URl to change from system to the name of your keyspace: netflix

✅ Populate HTTP HEADER variable x-cassandra-token on the bottom of the page with your token as shown below (again !! yes this is not the same tab)

Switch tabs

In order to insert data, you need to switch to the graphql tab.

If you try to insert the data in the graphql-schema tab, you will get the error you reported.

Set keyspace

You need to update the URI of your GraphQL playground in the graphql tab to use the keyspace name netflix instead of system. For example:

https://db_id-us-west1.apps.astra.datastax.com/api/graphql/system

change to:

https://db_id-us-west1.apps.astra.datastax.com/api/graphql/netflix

If you try to insert data into the system keyspace, you will get the error you reported because the reference_list table does not exist in that keyspace. Cheers!

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