amazon-web-services - 未找到字段的值 - AppSync AWS
问题描述
我目前正在使用 AppSync 来查询 GSI。我已经能够在 Pipeline Resolver 函数中成功使用此代码块,但是当我尝试在传统解析器中使用它时,我不知道为什么它不起作用。
我目前收到映射模板错误:
{
"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 检索 和文档: https ://docs.aws.amazon.com/appsync/latest/devguide/troubleshooting-and-common-mistakes.html#mapping -模板错误
这是请求映射模板:
#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]
注意:我创建了一个 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
是必需的:
版本
模板定义版本。当前支持 2017-02-28 和 2018-05-29。该值是必需的。
推荐阅读
- ios - iOS13 上的 Mapkit MapView VectorKit 崩溃
- javascript - 如何修复nodejs中的“无法读取未定义的属性“包含”?[脚本]
- angular - 将文件从客户端传递到 Firebase Cloud Function
- javascript - Angular 8 baseUrl 被消灭了
- xamarin - 在 Xamarin.Forms 中手动删除和添加元素到 App Shell 时如何暂停 UI / App Shell 更新?
- cytoscape.js - Cytoscape js - 每当单击节点时调用一个函数
- javascript - 赛普拉斯不处理异常
- laravel - 当响应是错误时,为什么承诺会进入 .then() ?- 拉拉维尔
- domain-driven-design - 聚合根的查询子项的存储库方法
- android - Android:没有cursorLoader的同一光标中的图像和视频路径