【发布时间】:2018-12-24 04:01:02
【问题描述】:
我正在使用 AWS AppSync 开发简单的消息应用程序。 这是我的架构:
type Conversation {
id: String!
messageIds: [String]
}
type ConversationConnection {
items: [Conversation]
nextToken: String
}
input CreateConversationInput {
id: String!
messageIds: [String]
}
input CreateMessageInput {
id: String!
text: String!
timestamp: String!
}
input CreateProfileInput {
id: Int!
name: String!
profileImage: String
isOnline: Boolean!
}
input DeleteConversationInput {
id: String!
}
input DeleteMessageInput {
id: String!
}
input DeleteProfileInput {
id: Int!
}
type Message {
id: String!
text: String!
timestamp: String!
}
type MessageConnection {
items: [Message]
nextToken: String
}
type Mutation {
createProfile(input: CreateProfileInput!): Profile
updateProfile(input: UpdateProfileInput!): Profile
deleteProfile(input: DeleteProfileInput!): Profile
createMessage(input: CreateMessageInput!): Message
updateMessage(input: UpdateMessageInput!): Message
deleteMessage(input: DeleteMessageInput!): Message
createConversation(input: CreateConversationInput!): Conversation
updateConversation(input: UpdateConversationInput!): Conversation
deleteConversation(input: DeleteConversationInput!): Conversation
updateConversationMessages(id: String!, messageIds: [String]): Conversation
}
type Profile {
id: Int!
name: String!
profileImage: String
isOnline: Boolean!
}
type ProfileConnection {
items: [Profile]
nextToken: String
}
type Query {
getProfile(id: Int!): Profile
listProfiles(first: Int, after: String): ProfileConnection
getMessage(id: String!): Message
listMessages(first: Int, after: String): MessageConnection
getConversation(id: String!): Conversation
listConversations(first: Int, after: String): ConversationConnection
}
type Subscription {
onCreateProfile(
id: Int,
name: String,
profileImage: String,
isOnline: Boolean
): Profile
@aws_subscribe(mutations: ["createProfile"])
onUpdateProfile(
id: Int,
name: String,
profileImage: String,
isOnline: Boolean
): Profile
@aws_subscribe(mutations: ["updateProfile"])
onDeleteProfile(
id: Int,
name: String,
profileImage: String,
isOnline: Boolean
): Profile
@aws_subscribe(mutations: ["deleteProfile"])
onCreateMessage(id: String, text: String, timestamp: String): Message
@aws_subscribe(mutations: ["createMessage"])
onUpdateMessage(id: String, text: String, timestamp: String): Message
@aws_subscribe(mutations: ["updateMessage"])
onDeleteMessage(id: String, text: String, timestamp: String): Message
@aws_subscribe(mutations: ["deleteMessage"])
onCreateConversation(id: String, messageIds: [String]): Conversation
@aws_subscribe(mutations: ["createConversation"])
onUpdateConversation(id: String, messageIds: [String]): Conversation
@aws_subscribe(mutations: ["updateConversation"])
onDeleteConversation(id: String, messageIds: [String]): Conversation
@aws_subscribe(mutations: ["deleteConversation"])
}
input UpdateConversationInput {
id: String!
messageIds: [String]
}
input UpdateMessageInput {
id: String!
text: String
timestamp: String
}
input UpdateProfileInput {
id: Int!
name: String
profileImage: String
isOnline: Boolean
}
到目前为止,我能够从客户端在 DynamoDB 上创建对话,但不能更新它们。 我试图编写一个解析器,但它不起作用:
{
"version": "2017-02-28",
"operation": "UpdateItem",
"key": {
"id": { "S": "${util.context.arguments.id}" }
}
"update": {
"expression": "SET List = :List",
"expressionValues": {
#set( $List = $context.arguments.List )
":List": $util.dynamodb.toListJson($List)
}
}
}
关于如何将最后一条消息的 id 附加到对话 messageIds 数组的任何想法? 谢谢。
【问题讨论】:
-
您能否分享为 AppSync 架构打开 CloudWatch Logs 并告诉您在那里看到的错误?乍一看,把
key对象改成"id" : { "S" : "${context.arguments.id}" }不带util可以试试。 -
@vahdet 这是我收到的日志“UpdateItem 需要提供更新表达式。”
标签: amazon-dynamodb graphql aws-appsync