未找到字段值 - AppSync AWS
Value for field not found - 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 文档中进行搜索,但将 "version" 添加到 GraphQL 类型无效。
我也试过了(尽管我没有使用 S3)
和文档:
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 table 的数据示例:
这是控制台中成功查询的屏幕截图:
注意:我创建了一个 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
是必需的:
version
The template definition version. 2017-02-28 and 2018-05-29 are currently supported. This value is required.
我目前正在使用 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 文档中进行搜索,但将 "version" 添加到 GraphQL 类型无效。
我也试过了(尽管我没有使用 S3)
这是请求映射模板:
#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 table 的数据示例:
这是控制台中成功查询的屏幕截图:
注意:我创建了一个 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
是必需的:
version
The template definition version. 2017-02-28 and 2018-05-29 are currently supported. This value is required.