如何解决AppSync中“表没有指定的索引”问题?

问题描述 投票:0回答:1

我使用 AWS AppSync 创建学习管理系统。放大版本是12.3.0。 我尝试使用 phoResultsByUserIdAndCreatedAt 查询,但收到此错误。

[错误]

The table does not have the specified index: phoResultsByUserIdAndCreatedAt (Service: DynamoDb, Status Code: 400, Request ID: FI38DQLTQEEV0KIPBPRFSU9JJVVV4KQNSO5AEMVJF66Q9ASUAAJG)

[schema.graphql]

type PhoResult @model @auth(rules: [{ allow: private, operations: [read, create, update, delete] }]) {
  id: ID! @primaryKey
  userId: ID! @index(sortKeyFields: ["createdAt"])
  materialId: ID!
  material: PhoMaterial @hasOne(fields: ["materialId"])
  materialGroupId: ID @index(sortKeyFields: ["createdAt"])
  materialGroup: PhoMaterialGroup @hasOne(fields: ["materialGroupId"])
  category: String
  kind: String! # normal / own
  topic: String
  level: Int
  lesson: Int
  group: String
  sentence: String!
  ipaSentence: String!
  ipaSentenceResult: String!
  qualityScore: Float
  soundFile: String
  wordList: [WordScoreList]
  lgmScoreTotal: Float
  lgmScorePhone: Float
  lgmScoreFrequency: Float
  lgmScoreStress: Float
  favoriteFlg: Int
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime
}

[查询]

query MyQuery {
  phoResultsByUserIdAndCreatedAt(userId: "7328af1f-9aa3-4782-9326-a19f19c7b86d", createdAt: {ge: "2023-07-01"}) {
    items {
      id
    }
  }
}
amazon-web-services amazon-dynamodb aws-amplify aws-appsync
1个回答
0
投票

解决方案可能是将索引添加到 DynamoDB 表或将调用中的索引名称更改为现有索引的名称。

Amplify 和 AppSync 等服务的问题在于它们固执己见。如果您使用它们自动创建其他服务(例如 DynamoDB 表和索引),它们将“决定”创建什么以及如何命名它们。通常,它使应用程序的创建变得更容易、更快,因为许多细节对您来说是隐藏的。然而,当您偏离幸福道路时,手动更改一些细节,可能会导致像您所面临的问题。

您可以决定打开引擎盖并开始检查和修改细节,例如添加或重命名索引,或者通过 Amplify 和 AppSync 重新启动该过程,减少或不进行可能导致上述偏离标准的更改。

© www.soinside.com 2019 - 2024. All rights reserved.