2

我了解枚举不是 Dynamo 中的标准类型:https ://forums.aws.amazon.com/thread.jspa?messageID=836386

但是,这里的确切分辨率是多少?我们应该如何恰当地表示与生成代码的关系?

-- 我是否遗漏了什么或者生成的代码是否正确,我们需要在发电机表中创建一些自定义字段,然后重写查询?

例子:

type Competition {
  id: ID!
  name: String!
  creator: UserProfile!
  startDate: String!
  endDate: String!
  competitionType: CompetitionType!
  competitors: [UserProfile]!
  prize: Prize!
}

竞赛是由用户创建的,有类型,有奖品,有竞争对手。create resources对于此表,代码显然缺少从自定义类型或枚举派生的任何信息。复杂的模式总是有这种类型的结构,所以我对输出的代码和从这里开始的正确方向有点困惑。

extend type Mutation {
    createCompetition(input: CreateCompetitionInput!): Competition
}

input CreateCompetitionInput {
  id: ID!
  name: String!
  startDate: String!
  endDate: String!
  ## Missing info
}
4

1 回答 1

2

当 AppSync 自动生成架构时,它会跳过这些,因为它们打算通过其他解析器手动添加。您可以定义一个附加到每个自定义或枚举字段的新查询,但您引用的数据需要标记竞争特有的内容,以便可以查询与此类型相关的数据(因为 dynamoDB 不是关系数据库)。

创建新比赛时,您需要使用该比赛独有的内容更新子字段。即,需要作为竞争对手进行跟踪的每个 UserProfile 都将使用该竞赛 ID 进行标记。每个自定义字段的突变需要单独处理。

这篇文章帮助我解决了同样的问题:https ://keyholesoftware.com/2018/05/17/go-forth-and-appsync/ 。

于 2018-05-24T18:08:12.980 回答