• AWS AppSync 的基本语句


    type Event {
        id: ID!
        name: String
        where: String
        when: String
        description: String
        # Paginate through all comments belonging to an individual post.
        comments(limit: Int, nextToken: String): CommentConnection
    }

     AWS AppSync 是API的一种新标准;Schema是它的核心,SDL是Schema的主要语言。

    schema {
        query: Query
        mutation: Mutation
        subscription: Subscription
    }
    1. query 查询语句:
    type Query {
        # Get a single event by id.
        getEvent(id: ID!): Event
        # Paginate through events.
        listEvents(filter: TableEventFilterInput, limit: Int, nextToken: String): EventConnection
    }

    例子:

    query{
      getEvent(id: "c16701cb-d614-4f21-b733-a636bc1c8437" ){
        description
        name
      }
    }

    返回 json:

    {
      "data": {
        "getEvent": {
          "description": "test",
          "name": "landen"
        }
      }
    }

      2. mutation 

    type Mutation {
        # Create a single event.
        createEvent(
            name: String!,
            when: String!,
            where: String!,
            description: String!
        ): Event
        # Delete a single event by id.
        deleteEvent(id: ID!): Event
        # Comment on an event.
        commentOnEvent(eventId: ID!, content: String!, createdAt: String!): Comment
    }
      • createEvent 添加事件    

            

    mutation{
      createEvent(
        name: "landen",
        when: "2018-08-18",
        where: "guangdong",
        description: "today is rainny"
      ){
        id
        name
      }
    }

    返回 json:

    {
      "data": {
        "getEvent": {
          "description": "test",
          "name": "landen"
        }
      }
    }
      •  commentOnEvent 更改事件:
      •   
    mutation{
      commentOnEvent(
        eventId: "c16701cb-d614-4f21-b733-a636bc1c8437",
        content: "comment : rainny",
        createdAt: "today"
      ){
        eventId
      }
    }

    返回 json:

    {
      "data": {
        "commentOnEvent": {
          "eventId": "c16701cb-d614-4f21-b733-a636bc1c8437"
        }
      }
    }
      • deleteEvent 删除事件:

    mutation{
      deleteEvent(id: "c16701cb-d614-4f21-b733-a636bc1c8437"){
        name 
        description
      }
    }

    返回 json:

    {
      "data": {
        "deleteEvent": {
          "name": "landen",
          "description": "test"
        }
      }
    }

      3.  subscription 订阅事件:

    type Subscription {
        subscribeToEventComments(eventId: String!): Comment
            @aws_subscribe(mutations: ["commentOnEvent"])
    }
    subscription{
      subscribeToEventComments(eventId:"b5a25e27-8416-4486-8df1-27c185520074"){
        content
        @aws_subscribe(  mutations:["commentOnEvent"])
      }
      
    }
  • 相关阅读:
    js操作cookie
    非常好的前端报表控件,值得收藏一下
    html5 跳到拨打电话功能
    C# 判断客户端是PC还是手机登录
    Oracle RAW类型使用
    多条Json数据转换为泛型数据
    将指定的对象序列化成 JSON 数据。
    ASP.NET MVC4(Razor)从客户端中检测到有潜在危险的 Request.Form 值
    http://v3.bootcss.com/getting-started/
    SQL日期比较 .
  • 原文地址:https://www.cnblogs.com/landen/p/9497825.html
Copyright © 2020-2023  润新知