zoukankan      html  css  js  c++  java
  • 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"])
      }
      
    }
  • 相关阅读:
    两指针--减少数组循环
    python与正则表达式
    python 获取网页图片
    python学习 第一天
    jquery中的基本理解以及样式属性操作
    webapi中的三大家族
    BOM中的其他对象以及短路运算
    BOM中的api
    事件冒泡和事件捕获
    webapi中注册事件以及解绑事件
  • 原文地址:https://www.cnblogs.com/landen/p/9497825.html
Copyright © 2011-2022 走看看