如何使用GraphQL API插入数据到Astra DB?
我正在尝试跟随此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 技术交流群。

您没有提供如何为 Ania 的 Netflix 克隆 教程,所以我假设您已经命名了您的键空间为
netflix
。您似乎没有正确遵循说明并错过了步骤。如果我至少跳过本教程中的一个步骤,我可以复制您报告的错误。
在 第 5 步在教程中,您需要执行以下操作:
切换选项卡
为了插入数据,您需要切换到
graphql
选项卡。如果您尝试在
graphql-schema
选项卡中插入数据,您将收到报告的错误。设置键空间
您需要在
graphql
选项卡中更新 GraphQL Playground 的 URI,以使用键空间名称netflix
而不是system
。例如:更改为:
如果您尝试将数据插入到
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:
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 namenetflix
instead ofsystem
. For example:change to:
If you try to insert data into the
system
keyspace, you will get the error you reported because thereference_list
table does not exist in that keyspace. Cheers!