首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AppSync突变

AppSync突变
EN

Stack Overflow用户
提问于 2018-07-16 14:53:19
回答 1查看 742关注 0票数 0

我正在用AWS AppSync开发简单的消息应用程序。这是我的模式:

代码语言:javascript
复制
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上创建会话,但不能更新它们。我试过用一个解析器,但它不起作用:

代码语言:javascript
复制
{
    "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数组,有什么想法吗?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-07-17 12:26:25

保留字存在于DynamoDB中,List是其中之一。在这种情况下,必须使用expressionNames属性。见文件中的部分

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

代码语言:javascript
复制
{
  "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)
    }
  }
}

对于一个更复杂的AppSync(UpdateItem)示例,您可以访问这里

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51364638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档