gpt4 book ai didi

amazon-web-services - 未找到字段值 - AppSync AWS

转载 作者:行者123 更新时间:2023-12-02 03:10:42 24 4
gpt4 key购买 nike

我当前正在使用 AppSync 来查询 GSI。我已经能够在管道解析器函数中成功使用此代码块,但我不知道为什么当我尝试在传统解析器中使用它时它不起作用。

我当前收到映射模板错误:

{
"data": {
"units": null
},
"errors": [
{
"path": [
"units"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Value for field '$[version]' not found."
}
]
}

我尝试在 AWS 文档中搜索,但向 GraphQL 类型添加“版本”不起作用。

我也尝试过这个(即使我没有使用S3) AppSync S3Object retrieval和文档: https://docs.aws.amazon.com/appsync/latest/devguide/troubleshooting-and-common-mistakes.html#mapping-template-errors

这是请求映射模板:

#set($arg=$context.args)

{
"operation": "Query",
"index" : "userPK-userSK-index",
"query": {
"expression": "userPK = :pk and begins_with(userSK, :sk)",
"expressionValues": {
":pk": {"S": "tenant:${arg.tenantId}" },
":sk": {"S": "school-year:${arg.schoolYear}:grades:${arg.gradeId}:subject:${arg.subjectId}:unit:"}
}
}
}

这是响应映射模板:

$util.toJson($ctx.result.items)

这是执行的 GraphQL 的片段:

query GetUnits{
units(tenantId: "5fc30406-346c-42e2-8083-fda33ab6000a"
schoolYear: "2019-2020"
gradeId: "c737e341-a0cb-4a16-95de-f3a092049e74"
subjectId: "d0306e25-422d-4628-8fcc-c354b67c932a") {
id
indicator {
id,
description
}
competency {
id,
description,
name
}
description,
name
}


}

以下是 GraphQL 架构的片段:


type Unit {
id: ID!
competency: Competency
indicator: Indicator
name: String!
description: String
version: Int
}

type Competency {
id: ID
# grade: Grade
# subject: Subject
# schoolYear: String
name: String
description: String
}

type Indicator {
id: ID!
description: String
}
type Query {
units(
tenantId: String!
schoolYear: String!
gradeId: String!
subjectId: String!
): [Unit]

以下是 DynamoDB 表中的数据示例: enter image description here

这是控制台中成功查询的屏幕截图: enter image description here

注意:我创建了一个 GSI,将 userPK 和 userSK 分别映射为分区键和排序键。我正在查询该二级索引。我已经能够使用控制台成功查询此信息。

最佳答案

错误表明您忘记了version参数。这是查询模板 ( docs ):

{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
"expression" : "some expression",
"expressionNames" : {
"#foo" : "foo"
},
"expressionValues" : {
":bar" : ... typed value
}
}
"index" : "fooIndex",
"nextToken" : "a pagination token",
"limit" : 10,
"scanIndexForward" : true,
"consistentRead" : false,
"select" : "ALL_ATTRIBUTES",
"filter" : {
...
}
}

并且需要版本:

version

The template definition version. 2017-02-28 and 2018-05-29 are currently supported. This value is required.

关于amazon-web-services - 未找到字段值 - AppSync AWS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57667928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com