Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GraphQL: A Horizontal Platform

Dan Schafer
November 17, 2015

GraphQL: A Horizontal Platform

GraphQL: A Horizontal Platform
Dan Schafer
Taipei, 17-18 November 2015
Singapore, 21 November 2015

Dan Schafer

November 17, 2015
Tweet

More Decks by Dan Schafer

Other Decks in Programming

Transcript

  1. { "me": { "name": "Daniel Schafer", "profilePicture": { "width": 50,

    "height": 50, "url": "https://cdn/50.jpg" } } } { me { name, profilePicture { width, height, url } } }
  2. { me { name, friends { name } } }

    { "me": { "name": "Daniel Schafer", "friends": [ { "name": "Lee Byron" }, { "name": "Nick Schrock" }, { "name": "Alex Langenfeld" },
  3. { me { name, friends { name, events { name

    } } } } { "me": { "name": "Daniel Schafer", "friends": [ { "name": "Lee Byron", "events": [ { "name": "GraphQL Team Dinner" }, { "name": "Bow Tie Conference" }, ] }
  4. { me { name, friends(orderby: IMPORTANCE, first: 1) { name,

    events(first: 1) { name } } } } type Query { me: User user(id: Int): User } { me }
  5. type User { name: String friends(first: Int, orderby: FriendOrderEnum): [User]

    events(first: Int): [Event] } enum FriendOrderEnum { FIRST_NAME, IMPORTANCE } { me { name, friends(orderby: IMPORTANCE, first: 1) { name, events(first: 1) { name } } } } { name, friends(orderby: IMPORTANCE, first: 1) }
  6. type User { name: String profilePicture(size: Int = 50): ProfilePicture

    friends(first: Int, orderby: FriendOrderEnum): [User] events(first: Int): [Event] } { me { name, friends(orderby: IMPORTANCE, first: 1) { name, events(first: 1) { name } } } } { name, events(first: 1) }
  7. type Event { name: String attendees(first: Int): [User] } {

    me { name, friends(orderby: IMPORTANCE, first: 1) { name, events(first: 1) { name } } } } { name }
  8. Models Models v2 Views v2 Views Here's your 123 v2

    model CLIENT Model: 123, v2, plz APP SERVER
  9. Models Models v2 Models v3 Views v3 Views v2 Views

    Here's your 123 v3 model CLIENT Model: 123, v3, plz APP SERVER
  10. Models v2 Models v3 Models v4 Views v4 Views v3

    Views v2 CLIENT Here's your 123 v4 model APP SERVER Model: 123, v4, plz
  11. Views v2 Views Models Models v2 This data shape, plz

    Here's your specific data CLIENT APP SERVER Type System
  12. Views v3 Views v2 Views Models Models v2 Models v3

    This data shape, plz Here's your specific data CLIENT APP SERVER Type System
  13. fragment friendFragment on User { } { me { name

    friends { ...friendFragment } } } name events { name }
  14. fragment timelineFragment on User { ...headerFragment ...aboutFragment } fragment headerFragment

    on User { name profilePicture coverPhoto } fragment aboutFragment on User { currentWork previousWork school }
  15. Feed Ranking & Storage User DB Link & Image Cache

    User DB Feed Ranking & Storage
  16. // type User { { // profilePicture(size: Int = 50):

    ProfilePicture profilePicture(user, {size}) { return user.profilePicture; }, // friends: [User] friends(user) { return user.friendIDs.map(id => promiseUser(id)); } }
  17. // type User { { // profilePicture(size: Int = 50):

    ProfilePicture profilePicture(user, {size}) { return user.profilePicture; }, // friends: [User] friends(user) { return user.friendIDs.map(id => promiseUser(id)); } } profilePicture(user, {size}) { return user.profilePicture; }
  18. // type User { { // profilePicture(size: Int = 50):

    ProfilePicture profilePicture(user, {size}) { return getProfilePicForUser(user, size); }, // friends: [User] friends(user) { return user.friendIDs.map(id => promiseUser(id)); } } profilePicture(user, {size}) { return getProfilePicForUser(user, size); }
  19. // type User { { // profilePicture(size: Int = 50):

    ProfilePicture profilePicture(user, {size}) { return getProfilePicForUser(user, size); }, // friends: [User] friends(user) { return user.friendIDs.map(id => promiseUser(id)); } } friends(user) { return user.friendIDs.map(id => promiseUser(id)); }
  20. { __schema { queryType { name } types { name

    fields { name, type { name, } } } } }
  21. { me { name, profilePicture { width, height, url }

    } } @interface GraphQLUser : NSObject { - (NSString *)name; - (GraphQLPic *)profilePicture; } @interface GraphQLProfilePicture - (NSNumber *)width; - (NSNumber *)height; - (NSString *)url; } Code Generation
  22. mutation { createComment( storyId: 37000641 text: “Hello” ) { comment

    { createTime } } } mutation { updateComment( commentId: 37000641 newText: “Hello” ) { comment { text } } }
  23. mutation { acceptFriendRequest( userId: 37000641 ) { user { friends

    { count } } } } mutation { eventRsvp( eventId: 37000641 status: ATTENDING ) { event { invitees { count } attendees { count } } } }
  24. Mobile Revolution Giant Leap Forward for Consumers A Big Step

    Backwards for Developers and Product Organizations
  25. React is Opinionated • Functional Programming • Immutable Data Structures

    • Declarative APIs • Rethinking Best Practices™