type Todo { id: ID! name: String description: String priority: Int duedate: String } Model data with application schema query { getTodos { id name priority } } Client requests what it needs { "id": "1", "name": "Get Milk", "priority": "1" }, { "id": "2", "name": "Go to gym", "priority": "5" },… Only that data is returned
Query-driven Client-driven development Use GraphQL When you leverage HTTP Caching, Content types Hypermedia For resources (e.g. Amazon S3) Use REST Pick the appropriate protocol for your use case
data source via Velocity Template to execute query / mutation. Response Resolver Maps response from data source to GraphQL response via Velocity Template.
Query appSyncClient?.fetch(query: GetHotelQuery(hotelId: hotelId), cachePolicy: .fetchIgnoringCacheData) {(result, error) in guard let r = result, error == nil else { print(error?.localizedDescription ?? "") return } // use the data in the GUI self.hotelDetails = r.data?.getHotel … }
record, modifying record in DynamoDB and triggering subscription DynamoDB Stream: Put event in queue for processing AWS Lambda AWS Lambda Amazon DynamoDB Amazon SNS Amazon SNS
userId) newReservationSubscription = try appSyncClient?.subscribe(subscription: sub, resultHandler: { (result, transaction, error) in // check for error // store a reference to the new booking into our cache transaction?.update(query: GuestReservationsQuery(guestId: userId)) { (data: inout GuestReservationsQuery.Data) in data.guestReservations?.append(bookingToAdd) // consume the data in the UI self.bookingDetails?.append(bookingToAdd) } }
API Incorporated legacy, new, and prototype features in a single endpoint Evolved API as requirements changed No coding required! Well, there were a few Velocity Templates AWS Console includes starter / boilerplate templates
any web/mobile developer to arbitrarily query basically any field in any backend service, recursively, however they want, without any backend developers involved? Frontend Dev: Yeah, right? It’s amazing! […silence…] Backend Dev: Guards, seize this person.