Slide 1

Slide 1 text

Dan Schafer @dlschafer Mysterious Closing Keynote

Slide 2

Slide 2 text

The Prehistory of GraphQL Dan Schafer @dlschafer

Slide 3

Slide 3 text

History of GraphQL July ’15 Aug ’12 Evolution Open Source Feb ’12 Today Prototype

Slide 4

Slide 4 text

History of GraphQL July ’15 Aug ’12 Evolution Open Source Feb ’12 Today Prototype re

Slide 5

Slide 5 text

Prehistory of GraphQL Aug ’12 Feb ’12 Prototype Feb ’08 Creation of 2012-era FB Server Architecture

Slide 6

Slide 6 text

⚠ This isn’t the “one true way”

Slide 7

Slide 7 text

✅ This was Facebook in 2012

Slide 8

Slide 8 text

# But GraphQL was built for this

Slide 9

Slide 9 text

$ …and it’s got some good ideas!

Slide 10

Slide 10 text

Why do we care?

Slide 11

Slide 11 text

“How do I implement authorization?” “How do I make my server efficient?” “How do I cache my results?”

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

One Layer Deeper

Slide 14

Slide 14 text

“How do I implement authorization?” “How do I make my server efficient?” “How do I cache my results?”

Slide 15

Slide 15 text

“How do I implement authorization?” “How do I make my server efficient?” “How do I cache my results?” GraphQL addresses
 none of these…

Slide 16

Slide 16 text

“How do I implement authorization?” “How do I make my server efficient?” “How do I cache my results?” …because these were already answered at FB in 2012…

Slide 17

Slide 17 text

“How do I implement authorization?” “How do I make my server efficient?” “How do I cache my results?” …because these are concerns not specific to GraphQL!

Slide 18

Slide 18 text

Prehistory of GraphQL Aug ’12 Feb ’12 Prototype Feb ’08 Creation of 2012-era FB Server Architecture

Slide 19

Slide 19 text

3 key architectural developments

Slide 20

Slide 20 text

Data requirements form a tree Asynchronicity is mandatory Strive for single sources of truth

Slide 21

Slide 21 text

Data requirements form a tree

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

I am not a designer

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

SELECT `users.name` FROM `friends` WHERE `id1` = 1 LEFT JOIN `users` as `u2` WHERE `users.bestId` = `u2.id` LEFT JOIN `friends` WHERE `users.id` = `friends.id1` LEFT JOIN `users` as `u3` WHERE `friends.id2 = u3.id` LEFT JOIN `users` as `u4` WHERE `u3.bestId` = `u4.id` query.sql

Slide 26

Slide 26 text

I am not a SQL engineer

Slide 27

Slide 27 text

SELECT `users.name` FROM `friends` WHERE `id1` = 1 LEFT JOIN `users` as `u2` WHERE `users.bestId` = `u2.id` LEFT JOIN `friends` WHERE `users.id` = `friends.id1` LEFT JOIN `users` as `u3` WHERE `friends.id2 = u3.id` LEFT JOIN `users` as `u4` WHERE `u3.bestId` = `u4.id` query.sql

Slide 28

Slide 28 text

Sharding

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

redis.log

Slide 32

Slide 32 text

GET cu GET u:2 LRANGE fr:1 0 5 GET u:3 GET u:4 GET u:5 GET u:6 GET u:7 GET u:8 GET u:9 GET u:10 GET u:11 GET u:12 redis.log {i:1 n:Dan bf:2} {i:2 n:Mary} [3,4,5,6,7] {i:3 n:Nick bf:8} {i:4 n:Lee bf:9} {i:5 n:Alex bf:10} {i:6 n:Laney bf:11} {i:7 n:Ola bf:12} {i:8 n:Leslie} {i:9 n:Ash} {i:10 n:Nina} {i:11 n:Turner} {i:12 n:Katie}

Slide 33

Slide 33 text

GET cu GET u:2 LRANGE fr:1 0 5 GET u:3 GET u:4 GET u:5 GET u:6 GET u:7 GET u:8 GET u:9 GET u:10 GET u:11 GET u:12

Slide 34

Slide 34 text

Dan GET cu GET u:2 LRANGE fr:1 0 5 GET u:3 GET u:4 GET u:5 GET u:6 GET u:7 GET u:8 GET u:9 GET u:10 GET u:11 GET u:12

Slide 35

Slide 35 text

Mary Friends Dan GET cu GET u:2 LRANGE fr:1 0 5 GET u:3 GET u:4 GET u:5 GET u:6 GET u:7 GET u:8 GET u:9 GET u:10 GET u:11 GET u:12

Slide 36

Slide 36 text

Laney Alex Lee Nick Ola Mary Friends Dan GET cu GET u:2 LRANGE fr:1 0 5 GET u:3 GET u:4 GET u:5 GET u:6 GET u:7 GET u:8 GET u:9 GET u:10 GET u:11 GET u:12

Slide 37

Slide 37 text

Turner Nina Ash Leslie Katie Laney Alex Lee Nick Ola Mary Friends Dan GET cu GET u:2 LRANGE fr:1 0 5 GET u:3 GET u:4 GET u:5 GET u:6 GET u:7 GET u:8 GET u:9 GET u:10 GET u:11 GET u:12

Slide 38

Slide 38 text

Turner Nina Ash Leslie Katie Laney Alex Lee Nick Ola Mary Friends Dan GET cu GET u:2 LRANGE fr:1 0 5 GET u:3 GET u:4 GET u:5 GET u:6 GET u:7 GET u:8 GET u:9 GET u:10 GET u:11 GET u:12

Slide 39

Slide 39 text

Turner Nina Ash Leslie Katie Laney Alex Lee Nick Ola Mary Friends Dan GET cu GET u:2 LRANGE fr:1 0 5 MGET u:3 u:4 u:5
 u:6 u:7
 
 
 GET u:8 GET u:9 GET u:10 GET u:11 GET u:12

Slide 40

Slide 40 text

Turner Nina Ash Leslie Katie Laney Alex Lee Nick Ola Mary Friends Dan GET cu GET u:2 LRANGE fr:1 0 5 MGET u:3 u:4 u:5
 u:6 u:7
 
 
 GET u:8 GET u:9 GET u:10 GET u:11 GET u:12

Slide 41

Slide 41 text

Turner Nina Ash Leslie Katie Laney Alex Lee Nick Ola Mary Friends Dan GET cu GET u:2 LRANGE fr:1 0 5 MGET u:3 u:4 u:5
 u:6 u:7
 
 
 MGET u:8 u:9 u:10
 u:11 u:12 
 


Slide 42

Slide 42 text

Turner Nina Ash Leslie Katie Laney Alex Lee Nick Ola Mary Friends Dan GET cu GET u:2 LRANGE fr:1 0 5 MGET u:3 u:4 u:5
 u:6 u:7
 
 
 MGET u:8 u:9 u:10
 u:11 u:12
 
 


Slide 43

Slide 43 text

Our data requirements formed a tree

Slide 44

Slide 44 text

That tree describes
 our data fetching strategy

Slide 45

Slide 45 text

How do we implement that?

Slide 46

Slide 46 text

Asynchronicity is mandatory

Slide 47

Slide 47 text

PHP5 primitives… are
 not asynchronous

Slide 48

Slide 48 text

GET cu GET u:2 LRANGE fr:1 0 5 MGET u:3 u:4 u:5
 u:6 u:7 MGET u:8 u:9 u:10
 u:11 u:12 redis.log {i:1 n:Dan bf:2} {i:2 n:Mary} [3,4,5,6,7] {i:3 n:Nick bf:8} {i:4 n:Lee bf:9} {i:5 n:Alex bf:10} {i:6 n:Laney bf:11} {i:7 n:Ola bf:12} {i:8 n:Leslie} {i:9 n:Ash} {i:10 n:Nina} {i:11 n:Turner} {i:12 n:Katie} getCurrentUser(); get(2); getFriends(1); get(3); get(4); get(5); get(6); get(7); get(8); get(9); get(10); get(11); get(12);

Slide 49

Slide 49 text

GET cu GET u:2 LRANGE fr:1 0 5 MGET u:3 u:4 u:5
 u:6 u:7 MGET u:8 u:9 u:10
 u:11 u:12 redis.log {i:1 n:Dan bf:2} {i:2 n:Mary} [3,4,5,6,7] {i:3 n:Nick bf:8} {i:4 n:Lee bf:9} {i:5 n:Alex bf:10} {i:6 n:Laney bf:11} {i:7 n:Ola bf:12} {i:8 n:Leslie} {i:9 n:Ash} {i:10 n:Nina} {i:11 n:Turner} {i:12 n:Katie} getCurrentUser(); DISPATCH() get(2); getFriends(1); DISPATCH() get(3); get(4); get(5); get(6); get(7); DISPATCH() get(8); get(9); get(10); get(11); get(12); DISPATCH()

Slide 50

Slide 50 text

getCurrentUser(); DISPATCH() get(2); getFriends(1); DISPATCH() get(3); get(4); get(5); get(6); get(7); DISPATCH() get(8); get(9); get(10); get(11); get(12); DISPATCH()

Slide 51

Slide 51 text

get_current_user(true, $user); memcache_dispatch(); get_user(2, true, $user2); get_friends(1, true, $friends); memcache_dispatch(); get_user(3, true, $user3); get_user(4, true, $user4); get_user(5, true, $user5); get_user(6, true, $user6); get_user(7, true, $user7); memcache_dispatch(); get_user(8, true, $user8); get_user(9, true, $user9); get_user(10, true, $user10); get_user(11, true, $user11); get_user(12, true, $user12); memcache_dispatch();

Slide 52

Slide 52 text

Yuck %

Slide 53

Slide 53 text

class MyPreparable extends Preparable { $some_data = null; $other_data = null; public function prepare($pass) { switch ($pass) { case 0: fetch_some_data($this->some_data) return true; case 1: fetch_other_data($this->some_data, $this->other_data) return false; } public function getData() { return $this->other_data; } } https://www.quora.com/Facebook-Infrastructure-What-are-preparables-and-how-are-they-implemented

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

https://www.infoq.com/presentations/Evolution-of-Code-Design-at-Facebook

Slide 56

Slide 56 text

https://www.infoq.com/presentations/Evolution-of-Code-Design-at-Facebook

Slide 57

Slide 57 text

class MyPreparable extends Preparable { $some_data = null; $other_data = null; public function prepare($pass) { switch ($pass) { case 0: fetch_some_data($this->some_data) return true; case 1: fetch_other_data($this->some_data, $this->other_data) return false; } public function getData() { return $this->other_data; } } https://www.quora.com/Facebook-Infrastructure-What-are-preparables-and-how-are-they-implemented

Slide 58

Slide 58 text

https://gu.illau.me/posts/polyfilling-generators/

Slide 59

Slide 59 text

class MyPreparable extends Preparable { $some_data = null; $other_data = null; public function prepare($pass) { switch ($pass) { case 0: fetch_some_data($this->some_data) return true; case 1: fetch_other_data($this->some_data, $this->other_data) return false; } public function getData() { return $this->other_data; } } https://www.quora.com/Facebook-Infrastructure-What-are-preparables-and-how-are-they-implemented

Slide 60

Slide 60 text

Double Yuck % %

Slide 61

Slide 61 text

We spent so much time iterating on async primitives

Slide 62

Slide 62 text

You don’t have to

Slide 63

Slide 63 text

async/await

Slide 64

Slide 64 text

GET cu GET u:2 LRANGE fr:1 0 5 MGET u:3 u:4 u:5
 u:6 u:7 MGET u:8 u:9 u:10
 u:11 u:12 redis.log {i:1 n:Dan bf:2} {i:2 n:Mary} [3,4,5,6,7] {i:3 n:Nick bf:8} {i:4 n:Lee bf:9} {i:5 n:Alex bf:10} {i:6 n:Laney bf:11} {i:7 n:Ola bf:12} {i:8 n:Leslie} {i:9 n:Ash} {i:10 n:Nina} {i:11 n:Turner} {i:12 n:Katie} getCurrentUser(); get(2); getFriends(1); get(3); get(4); get(5); get(6); get(7); get(8); get(9); get(10); get(11); get(12);

Slide 65

Slide 65 text

GET cu GET u:2 LRANGE fr:1 0 5 MGET u:3 u:4 u:5
 u:6 u:7 MGET u:8 u:9 u:10
 u:11 u:12 redis.log {i:1 n:Dan bf:2} {i:2 n:Mary} [3,4,5,6,7] {i:3 n:Nick bf:8} {i:4 n:Lee bf:9} {i:5 n:Alex bf:10} {i:6 n:Laney bf:11} {i:7 n:Ola bf:12} {i:8 n:Leslie} {i:9 n:Ash} {i:10 n:Nina} {i:11 n:Turner} {i:12 n:Katie} await genCurrentUser(); await Promise.all( gen(2), genFriends(1) ); await Promise.all( [3,4,5,6,7].map(x => gen(x)) ); await Promise.all( [8,9,10,11,12].map(x => gen(x)) );

Slide 66

Slide 66 text

Design your server abstractions around async primitives

Slide 67

Slide 67 text

GraphQL did!

Slide 68

Slide 68 text

The Book of GraphQL Chapter 6 Verse 4.2

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

Asynchronicity is mandatory

Slide 72

Slide 72 text

Strive for single sources of truth

Slide 73

Slide 73 text

“How do I implement authorization?” “How do I make my server efficient?” “How do I cache my results?”

Slide 74

Slide 74 text

“How do I implement authorization?” “How do I make my server efficient?” “How do I cache my results?” Always want to get
 these things right

Slide 75

Slide 75 text

“How do I implement authorization?” “How do I make my server efficient?” “How do I cache my results?” Only want to write
 them once!

Slide 76

Slide 76 text

Objects

Slide 77

Slide 77 text

http://sujaytrivedi.blogspot.com/2015/03/object-oriented-programming-oop-in-c.html

Slide 78

Slide 78 text

https://upload.wikimedia.org/wikipedia/commons/b/b8/Policy_Admin_Component_Diagram.PNG

Slide 79

Slide 79 text

Smart data objects

Slide 80

Slide 80 text

Smart data objects FB Jargon: Ent, short for “Entity”

Slide 81

Slide 81 text

Smart data objects FB Jargon: Ent, short for “Entity”

Slide 82

Slide 82 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise {} getID(): string {} getName(): string {} genBestFriend(): Promise {} genProfilePhoto(): Promise {} }

Slide 83

Slide 83 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise {} getID(): string {} getName(): string {} genBestFriend(): Promise {} genProfilePhoto(): Promise {} }

Slide 84

Slide 84 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise { const data = await genUserFromDb(id); if (!data) { return null; } const canSee = await genCanViewerSeeUser(viewer, data); if (!canSee) { return null; } return new SmartUser(viewer, id, data); } }

Slide 85

Slide 85 text

Single Source of Truth

Slide 86

Slide 86 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise {} getID(): string {} getName(): string {} genBestFriend(): Promise {} genProfilePhoto(): Promise {} }

Slide 87

Slide 87 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise {} getID(): string {} getName(): string {} genBestFriend(): Promise {} genProfilePhoto(): Promise {} }

Slide 88

Slide 88 text

class SmartUser { genBestFriend(): Promise { return SmartUser.gen(this.viewer, this.data.bestFriendId); } genProfilePhoto(): Promise { return SmartPhoto.gen(this.viewer, this.data.profilePhotoId); } }

Slide 89

Slide 89 text

Avoid overfetching

Slide 90

Slide 90 text

class SmartUser { static gen(viewer: Viewer, id: string): Promise genBestFriend(): Promise genProfilePhoto(): Promise }

Slide 91

Slide 91 text

function getBestFriendsProfilePhoto( viewer: Viewer, id: string ): Promise { const user = await SmartUser.gen(viewer, id); if (user == null) { return null; } const bestFriend = await user.genBestFriend(); if (bestFriend == null) { return null; } return await bestFriend.genProfilePhoto(); } class SmartUser { static gen(viewer: Viewer, id: string): Promise genBestFriend(): Promise genProfilePhoto(): Promise }

Slide 92

Slide 92 text

Self-reinforcing

Slide 93

Slide 93 text

Preconditioning

Slide 94

Slide 94 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise {} getID(): string {} getName(): string {} genBestFriend(): Promise {} genProfilePhoto(): Promise {} }

Slide 95

Slide 95 text

These seem familiar…

Slide 96

Slide 96 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise {} getID(): string {} getName(): string {} genBestFriend(): Promise {} genProfilePhoto(): Promise {} }

Slide 97

Slide 97 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise {} getID(): string {} getName(): string {} genBestFriend(): Promise {} genProfilePhoto(): Promise {} } GraphQL Object Type!

Slide 98

Slide 98 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise {} getID(): string {} getName(): string {} genBestFriend(): Promise {} genProfilePhoto(): Promise {} } GraphQL Fields!

Slide 99

Slide 99 text

class SmartUser { static gen( viewer: Viewer, id: string ): Promise {} getID(): string {} getName(): string {} genBestFriend(): Promise {} genProfilePhoto(): Promise {} } GraphQL Root Field
 (a.k.a. a field on Query)

Slide 100

Slide 100 text

Shouldn’t Resolvers contain 
 your business logic?

Slide 101

Slide 101 text

Resolvers map to
 your business logic!

Slide 102

Slide 102 text

Thin API layer

Slide 103

Slide 103 text

The Prehistory of GraphQL

Slide 104

Slide 104 text

The Future of GraphQL

Slide 105

Slide 105 text

History of GraphQL July ’15 Aug ’12 Evolution Open Source Feb ’12 Today Prototype

Slide 106

Slide 106 text

History of GraphQL July ’15 Aug ’12 Evolution Open Source Feb ’12 Today Prototype

Slide 107

Slide 107 text

Future of GraphQL July ’15 Open Source Today

Slide 108

Slide 108 text

Future of GraphQL July ’15 Open Source Today June 20–21, 2019

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

Future of GraphQL July ’15 Open Source Today

Slide 111

Slide 111 text

What might we talk about?
 


Slide 112

Slide 112 text

What might we talk about?
 
 What might we work on?

Slide 113

Slide 113 text

Tooling Clients Servers

Slide 114

Slide 114 text

Tooling Clients Servers ✅ ✅ ❓

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

GraphQL Implementions
 ✅

Slide 117

Slide 117 text

GraphQL Implementions
 GraphQL-aware server stacks ✅ ❓

Slide 118

Slide 118 text

GraphQL Native Servers

Slide 119

Slide 119 text

We need
 Opinionated Server Frameworks

Slide 120

Slide 120 text

Data requirements form a tree Asynchronicity is mandatory Strive for single sources of truth

Slide 121

Slide 121 text

Thank you! Dan Schafer @dlschafer