未找到字段值 - AppSync AWS

Jos*_*e A 2 amazon-web-services amazon-dynamodb graphql aws-appsync

我当前正在使用 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."
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我尝试在 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:"}
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是响应映射模板:

$util.toJson($ctx.result.items)
Run Code Online (Sandbox Code Playgroud)

以下是执行的 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
}


}
Run Code Online (Sandbox Code Playgroud)

以下是 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]

Run Code Online (Sandbox Code Playgroud)

以下是 DynamoDB 表中的数据示例: 在此输入图像描述

以下是控制台中成功查询的屏幕截图: 在此输入图像描述

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

Ped*_*tes 5

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

{
    "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" : {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

并且version需要:

版本

模板定义版本。目前支持 2017-02-28 和 2018-05-29。该值是必需的。