Typescript + Graphql =

18
Par Félix Billon

Transcript of Typescript + Graphql =

Page 1: Typescript + Graphql =

Par Félix Billon

Page 2: Typescript + Graphql =

QUI SUIS-JE ?Développeur web orienté front-end chez Dcube.

Blog dev web : shakedatcode.fr

@felix_billon

Page 3: Typescript + Graphql =

SOMMAIRE1. API Gateway Pattern2. GraphQl3. TypeScript dans tout ça ?

Page 4: Typescript + Graphql =

MONOLITICS VS MICROSERVICES

Page 5: Typescript + Graphql =

MICROSERVICES : PROBLÈME...

Page 6: Typescript + Graphql =

API GATEWAY PATTERN

Page 7: Typescript + Graphql =

API GATEWAY PATTERN

Page 8: Typescript + Graphql =

API GATEWAY PATTERN : AVANTAGESMoins d’aller-retour client/services.Simplification du code client.Centralisation des middlewares (authentification,logging, controle du traffic, ...).Le client doit connaitre un seul endpoint.

Page 9: Typescript + Graphql =

API GATEWAY PATTERN :DÉSAVANTAGES

Ajout d'un nouveau composant.Doit être HAUTEMENT disponible.Doit connaître les endpoints des services.

Page 10: Typescript + Graphql =

GRAPHQL : EN BREFSpécification !By Facebook.Open source depuis 2015.Grosse communauté.Beaucoup d'outils disponible : GraphiQL, GraphQLVoyager, GraphQL Docs, ...

Page 11: Typescript + Graphql =

GRAPHQL : EN BREF

Page 12: Typescript + Graphql =

GRAPHQL : TYPE ET SCHÉMAtype Query { user(id: Int): User} type Mutation { createUser(firstName: String!, lastName: String!): User!} type User { id: Int! firstName: String! lastName: String! posts: [Post]} type Post { id: Int! title: String!}

Page 13: Typescript + Graphql =

GRAPHQL : RESOLVERexport const resolvers = { Query: { user: (obj, args, context) => { return users.find((user) => user.id === args.id); } }, Mutation: { createUser: (root, args) => { const newUser = { id: users.length + 1, firstName, lastName } users.push(newUser); return newUser; } }, User: { posts(user) {

t t filt (( t) > t i d Of( t id) ! 1)

Page 14: Typescript + Graphql =

GRAPHQL : QUERYRessemble très fortement à du JSON.

{ user(id: "10") { id firstName posts { title } }}

{ "data": { "user": { "id": 1, "firstName": "Felix", "posts": [ { "title": "Paris TypeScript #1 was awesome" }, { "title": "BestOfWeb rocks" } ] } }}

Page 15: Typescript + Graphql =

GRAPHQL : DEEP DIVESubscription : permet de cabler un système dePubSub.Dataloader : optimisation des requêtes.Introspection du graph.

Page 16: Typescript + Graphql =

GRAPHQL : CLIENT

Page 17: Typescript + Graphql =

TYPESCRIPT DANS TOUS ÇA ?Génération automatique des annotations de types àpartir du schéma et des requêtes (apollo-codegen,gql2ts, ts2gql, ...)Language service (ts-graphql-plugin, graphql-language-service, ...)

Page 18: Typescript + Graphql =

DEMO TIME