Amazon dynamodb AppSync突变

Amazon dynamodb AppSync突变,amazon-dynamodb,graphql,aws-appsync,Amazon Dynamodb,Graphql,Aws Appsync,我正在使用AWS AppSync开发简单消息应用程序。 这是我的模式: type Conversation { id: String! messageIds: [String] } type ConversationConnection { items: [Conversation] nextToken: String } input CreateConversationInput { id: String! messageIds: [Stri

我正在使用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附加到对话MessageID数组中吗? 谢谢。

DynamoDB中有,其中有
列表。在这种情况下,必须使用
expressionNames
属性。见:

最后,DynamoDB保留了表达式中不能出现的字。[…],我们可以使用名称占位符,并在expressionNames字段中将其定义为:

有关更复杂的AppSync DynamoDB(UpdateItem)示例,您可以访问。

DynamoDB中有,其中有
列表。在这种情况下,必须使用
expressionNames
属性。见:

最后,DynamoDB保留了表达式中不能出现的字。[…],我们可以使用名称占位符,并在expressionNames字段中将其定义为:


有关更复杂的AppSync DynamoDB(UpdateItem)示例,您可以访问。

是否可以共享打开AppSync架构的CloudWatch日志,并告诉您在那里看到的错误?乍一看,可以尝试将
对象更改为
“id”:{“S”:“${context.arguments.id}”
而不使用
util
。@vahdet这是我得到的日志“UpdateItem需要提供一个更新表达式”。您可以共享打开AppSync架构的CloudWatch日志并告诉您在那里看到的错误吗?乍一看,可以尝试将
对象更改为
“id”:{“S”:“${context.arguments.id}”
而不使用
util
。@vahdet这是我得到的日志“UpdateItem需要提供一个更新表达式。”非常好的解释@vahdet。我有一个关于这个论点的建议。当我查看更新会话updateConversation(输入:UpdateConversationInput!):conversation的模式时,参数就是输入。为了访问id,我们应该做一些类似$context.arguments.input.id的事情(较短的版本:$ctx.args.input.id)伟大的解释@vahdet。我有一个关于这个论点的建议。当我查看更新会话updateConversation(输入:UpdateConversationInput!):conversation的模式时,参数就是输入。要访问id,我们应该执行类似$context.arguments.input.id的操作(较短的版本:$ctx.args.input.id)
{
  "version": "2017-02-28",
  "operation": "UpdateItem",
  "key": {
    "id": { "S": "${context.arguments.id}" }
  },
  "update": {
    "expression": "SET #List = :List",
    "expressionNames": {
      "#List" : "List"
    },
    "expressionValues": {
      #set( $List = $context.arguments.List )
      ":List": $util.dynamodb.toListJson($List)
    }
  }
}