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 }
- 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"]) } }
用我拥有,换你没有,竭尽所有