我正在构建连接到DynamoDB的AWS AppSync graphQL服务器,该服务器正在使用复合键(假设postID对于HASH来说是唯一的,而RANGE对于clientID是唯一的)。
GraphQL规范要求使用unique ID。
为了让我从DynamoDB获取项目,我需要同时传递它们。为了遵循graphQL规范,我应该如何处理模式?
我将根据postID + clientID创建graphQL ID构建吗?有没有标准化的方法?
我可能会过度阅读规范,总是要求也将clientID传递给查询和突变是完全可以的,但是我找不到明确的答案。我尚未与Relay合作,所以我不确定它来回发送的内容。
答案 0 :(得分:1)
是的,在AppSync中可以要求有clientId。
有关设计架构的信息,请参阅AppSync文档:https://docs.aws.amazon.com/appsync/latest/devguide/designing-your-schema.html
尤其是文档中的一部分,我将在这里解释。
假设您有评论类型
protocol Animations {
func wiggle()
}
extension Animations where Self: UIView {
func wiggle() {
let position = "position"
let wiggleAnimation = CABasicAnimation(keyPath: position)
wiggleAnimation.duration = 0.05
wiggleAnimation.repeatCount = 5
wiggleAnimation.autoreverses = true
wiggleAnimation.fromValue = CGPoint(x: self.center.x - 4.0, y: self.center.y)
wiggleAnimation.toValue = CGPoint(x: self.center.x + 4.0, y: self.center.y)
layer.add(wiggleAnimation, forKey: position)
}
}
在这种情况下,有两个ID,并且都需要两个ID,因为这对应于DynamoDB主键+排序键组合。您将这些字段映射到解析器映射模板中的DynamoDB中的键。
模板看起来像:
type Comment {
todoid: ID!
commentid: String!
content: String
}
简而言之,如果您使用的DynamoDB表具有两个hash + sort键,则在AppSync中鼓励将它们作为GraphQL类型上的必填字段。