Slide 1

Slide 1 text

GraphQL đź’™ Kotlin LAUG - Feb 2024

Slide 2

Slide 2 text

apollographql/apollo-kotlin Hi đź‘‹

Slide 3

Slide 3 text

The beginnings of GraphQL 3 2012: Facebook

Slide 4

Slide 4 text

GraphQL describes your product Graph 4 Feed Post Post Ad Title Text XL Thumbnail S Thumbnail

Slide 5

Slide 5 text

5 Feed Post Post Ad Title Text XL Thumbnail S Thumbnail GraphQL

Slide 6

Slide 6 text

6 Feed Post Post Ad Title Text XL Thumbnail S Thumbnail GraphQL

Slide 7

Slide 7 text

7 Feed Post Post Ad Title Text XL Thumbnail S Thumbnail GraphQL

Slide 8

Slide 8 text

Le client récupère uniquement les données nécessaires No overfetching

Slide 9

Slide 9 text

Le schema décrit le type des données Strongly typed

Slide 10

Slide 10 text

Type system 10 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List }

Slide 11

Slide 11 text

â—Ź Objects Type system 11 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List }

Slide 12

Slide 12 text

â—Ź Objects â—Ź Scalars â—‹ Boolean Type system 12 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List }

Slide 13

Slide 13 text

â—Ź Objects â—Ź Scalars â—‹ Boolean â—‹ Int â—‹ Float â—‹ String Type system 13 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List }

Slide 14

Slide 14 text

â—Ź Objects â—Ź Scalars â—‹ Boolean â—‹ Int â—‹ Float â—‹ String Type system 14 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List }

Slide 15

Slide 15 text

â—Ź Objects â—Ź Scalars â—‹ Boolean â—‹ Int â—‹ Float â—‹ String â—Ź Lists Type system 15 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List }

Slide 16

Slide 16 text

â—Ź Interfaces â—Ź Unions Polymorphisme 16 interface Node { id: String } type User implements Node { id: String login: String bio: String [...] }

Slide 17

Slide 17 text

Nullability! 17 type User { login: Stringâť— bio: String isBountyHunter: Booleanâť— status: UserStatus issueComments: Listâť— }

Slide 18

Slide 18 text

❤

Slide 19

Slide 19 text

Autres propriétés de GraphQL 19 ● No overfetching ● Strongly typed ● Introspection ● No versioning ● Transport agnostic

Slide 20

Slide 20 text

Mise en pratique 1 https://confetti-app.dev/sandbox/

Slide 21

Slide 21 text

apollographql/apollo-kotlin

Slide 22

Slide 22 text

Automatic code generation 22 user.graphql schema.sdl Swift, Kotlin, Golang, JS, Rust, etc...

Slide 23

Slide 23 text

Codegen 23 { sessions { nodes { language title startsAt speakers { name } } } } class Session(val nodes: List) class Node( val language: String, val title: String, val startsAt: DateTime, val speakers: List ) class Speaker(val name: String)

Slide 24

Slide 24 text

Depreciation 24 class Node( @Deprecated("startsAt uses non ISO 8601 format, use startDateTime instead") val startsAt: String, ) type Conference { startsAt: String @deprecated(reason: "startsAt uses non ISO 8601 format, use startDateTime instead") startDateTime: DateTime }

Slide 25

Slide 25 text

Le schema évolue progressivement et utilise les mêmes règles de depreciations que Kotlin No versioning

Slide 26

Slide 26 text

❤

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Mise en pratique 2

Slide 29

Slide 29 text

GraphQL vs REST REST GraphQL resources graph multiple routes single endpoint swagger/open API builtin tooling versioning continuous evolution static queries dynamic queries

Slide 30

Slide 30 text

What if GraphQL is REST?

Slide 31

Slide 31 text

Persisted queries { sessions { nodes { language title startsAt speakers { name } } } } 57e2978c855b25cf5de4ba4a0160cf7402b3f393 Enregistrement des queries pendant le build

Slide 32

Slide 32 text

Persisted queries GET confetti-app.dev/graphql?operationId=57e2978c855b25cf5de4ba4a0160cf7402b3f393 { "data": { "sessions": { "nodes": [ { "language": "en-US", "title": "Android Graphics: the Path to [UI] Riches", "startsAt": "2023-04-27T09:15", "speakers": [ { "name": "Chet Haase" }, { "name": "Romain Guy" } ] }

Slide 33

Slide 33 text

Le futur

Slide 34

Slide 34 text

A brief history of 2012 Inception at meta 2015 Open source 2018 GraphQL Foundation SDL 2021 Last spec version You are here Nullability 2024 Draft Deprecated input values Full unicode

Slide 35

Slide 35 text

Non-Null String String! Nullable String? String 🤔

Slide 36

Slide 36 text

Merci đź’™ apollographql/apollo-kotlin martinbonnin https://openfeedback.io/zezxF16ZYW2DQCjMZDoj