XebiCon'16 : GraphQL et Falcor, un nouveau regard sur les architectures REST ? Par Antoine Le Taxin et Abdelhakim Bachar, Développeurs Front-End chez Xebia

Publicis Sapient Engineering
Publicis Sapient EngineeringCabinet IT à Publicis Sapient Engineering
@xebiconfr #xebiconfr
GraphQL et Falcor, un
nouveau regard sur les
architectures REST
Abdelhakim
Bachar
Antoine
Le Taxin
@xebiconfr #xebiconfr
Qui sommes-nous ?
Abdelhakim Bachar
@a_bachar
2
Antoine Le Taxin
@modulom
@xebiconfr #xebiconfr
Super, un nouveau projet !
1
3
@xebiconfr #xebiconfr
Besoin
GraphQL for iOS par Simone Civetta
GraphQL est une technologie dont vous avez entendu parler, peut-être, de vos collègues
Front. Il s’agit d’une API middleware, similaire à un ESB, qui…
Tags: Front, GraphQL, FalcorJS, React
Commentaires
Par Abdelhakim Bachar, Il y a 3 mois
An awesome article
Par Antoine Le Taxin, Il y a 3 mois
Wow.. Thanks much for sharing..
4
1a
5 articles, 30 commentaires
@xebiconfr #xebiconfr
RESTful (representational state transfer)
✔ Possibilité de cache
✔ Indépendance entre le modèle et la vue
5
1b
{
"id": 1,
"title": "Lorem ipsum",
"authorId": 1000
}
{
"id": 1000,
"lastName": "Carver",
"firstName": "Kerry"
}
✘ Latence (grand nombre de requêtes ou réponse lourde)
✘ Over fetching
[GET]/post/1 [GET]/user/1000
@xebiconfr #xebiconfr
L’approche GraphQL
2
6
@xebiconfr #xebiconfr
Qu’est ce que GraphQL ?
● Est une Spécification
● Implémentée en plusieurs langages de programmation
● Définit un langage permettant de requêter et récupérer de
manière déclarative des données depuis un back-end
7
2a
@xebiconfr #xebiconfr
Trois points d’histoire
● Créé par Facebook
● Remplacer tous les services REST nécessaires aux applications
mobile
● En production depuis 2012 pour les applications iOS et Android
de Facebook
8
2b
@xebiconfr #xebiconfr
Objectif
Avoir un outil puissant, productif et rétrocompatible pour développer
des applications
9
2c
@xebiconfr #xebiconfr
A quoi ressemble une requête ?
10
2d
// Résultat
{
"user": {
"id": 123456
"name": "Abdelhakim B."
}
}
// Requête GraphQL
{
user(id: 123456) {
id
name
}
}
@xebiconfr #xebiconfr
Les Concepts de Base
● Hiérarchique
● Requêtes spécifiques au client
● Typage fort
● Rétrocompatibilité
● Introspectif
● Indépendant du transport
11
2e
@xebiconfr #xebiconfr
Hiérarchique
12
2f
{
user(id: 1000) {
name
friends {
id
name
}
}
}
@xebiconfr #xebiconfr
Requêtes spécifiques au client
13
2g
Serveur
Possibilités
Client
Besoins
@xebiconfr #xebiconfr
const UserType = new GraphQLObjectType({
name: 'User',
description: 'Define a user resource',
fields: () => ({
firstName: {
type: GraphQLString, resolve: tag => tag.label
},
posts: {
type: new GraphQLList(PostType),
resolve: tag => tag.getPosts()
}
})
});
Typage fort
14
2h
@xebiconfr #xebiconfr
const UserType = new GraphQLObjectType({
fields: () => ({
fullName: {
type: GraphQLString,
isDeprecated: true,
deprecationReason: "You don't need it",
resolve: user => `${user.firstName} ${user.lastName}`
}
})
});
Rétrocompatibilité
15
2i
@xebiconfr #xebiconfr
Introspectif
16
2j
{
__type(name: "User") {
name
kind
}
}
{
"data": {
"__type": {
"name": "User",
"kind": "OBJECT"
}
}
}
@xebiconfr #xebiconfr
Introspectif: Génération de la documentation
17
2k
@xebiconfr #xebiconfr
Indépendant du transport
18
2l
WebSocket
@xebiconfr #xebiconfr
Que des requêtes ?
Non, pas seulement les requêtes, mais aussi la création, la mis à jour
et la suppression grâce au Mutation
19
2m
@xebiconfr #xebiconfr
Comment requêter un serveur GraphQL ?
POST
curl -XPOST -d 'query { user { name } }' http://localhost:3000
GET
http://localhost:3000/graphql?query={user{name}}
20
2n
@xebiconfr #xebiconfr
app.use('/graphql', expressGraphql({
schema,
pretty: true,
graphiql: true
}));
GraphQL HTTP Server Middleware
21
2o
@xebiconfr #xebiconfr
const schema = new GraphQLSchema({
query: queryType,
mutation: mutationType
});
GraphQL Schema
22
2p
@xebiconfr #xebiconfr
const queryType = new GraphQLObjectType({
name: 'Query',
description: 'Root query entry point',
fields: () => ({
users: UserQuery,
posts: PostQuery,
// ...
})
});
GraphQL Query
23
2q
@xebiconfr #xebiconfr
const UserQuery = {
type: new GraphQLList(UserType),
args: {
id: { type: GraphQLInt },
firstName: { type: GraphQLString },
// ...
},
resolve: (root, args) => User.findAll({where: args})
};
UserQuery
24
2s
@xebiconfr #xebiconfr
const UserType = GraphQLObjectType({
name: 'User',
description: 'Blog user',
fields: () => ({
id: {
type: GraphQLInt,
resolve: u => u.id
},
firstName: { type: GraphQLString },
posts: {
type: new GraphQLList(PostType),
resolve: u => u.getPosts()
}
})
});
Type User
25
2t
@xebiconfr #xebiconfr
const mutationType = new GraphQLObjectType({
name: "Mutation",
description: "Root mutation entry point",
fields: () => ({
createUser: {
type: UserType,
args: { firstName: {type: new GraphQLNonNull(GraphQLString)} },
resolve: (source, args) => User.create(Object.assign({}, args))
}
})
});
GraphQL Mutation
26
2r
@xebiconfr #xebiconfr
{
posts(name: 12549) {
id
title
content
author {
id
firstName
lastName
}
comments {
content
author {
id
firstName
lastName
count_comments
count_posts
}
}
}
}
La requête pour notre blog
27
2u
GraphQL for iOS par Simone Civetta
GraphQL est une technologie dont vous avez
entendu parler, peut-être, de vos collègues
Front. Il s’agit d’une API middleware, similaire
à un ESB, qui…
Tags: Front, GraphQL, FalcorJS, React
Commentaires
Par Abdelhakim Bachar, Il y a 3 mois
An awesome article
Par Antoine Le Taxin, Il y a 3 mois
Wow.. Thanks much for sharing..
5 articles, 30 commentaires
@xebiconfr #xebiconfr
L’approche Falcor
3
28
@xebiconfr #xebiconfr
● Est un librairie Javascript open source
● Propose une manière impérative de décrire et d’accéder aux
données
● Embarque un système de cache et d’optimisation de requêtes
Qu’est ce que Falcor ?
29
3a
@xebiconfr #xebiconfr
● Créé par Netflix
● Répond aux besoins de performance, d’éclatement de leur
sources de données et diversité des supports
● En production pour leur applications TV, mobile et desktop et
open source depuis 2015
Trois points d’histoire
30
3b
@xebiconfr #xebiconfr
Avoir un outil centré sur la performance et le cloud, spécialement
adapté aux architectures microservices.
Objectif
31
3c
@xebiconfr #xebiconfr
A quoi ressemble une requête ?
32
3d
// Résultat
{
"user": {
"name": "Abdelhakim B."
}
}
// Requête falcor
model
.get('users[0].name')
.then(
//
)
@xebiconfr #xebiconfr
Les Concepts de Base
33
3e
Paths
JSON Graph
Data SourcesRouter
Model
@xebiconfr #xebiconfr
● Langage de query de Falcor
● Exprime un chemin au travers d’un objet JSON
● Il accepte deux syntaxes :
○ Syntaxe Path String
○ Array de clés
'posts[1].title'
['posts', 1, 'title']
'posts[1..2]['title','content']'
['posts', {from: 1, to: 2}, ['title','content']]
Paths
34
3f
@xebiconfr #xebiconfr
● On accède aux données au travers d’un graph JSON unique
(quelque soit le nombre de sources)
// frontend
var model = new falcor.Model({
source: new falcor.HttpDataSource('api/model.json')
})
// backend
app.use('/api/model.json', falcorExpress.dataSourceRoute((req, res) =>
{
return new Router([ (...) ])
}
)
Model
35
3g
@xebiconfr #xebiconfr
● Retourne les données de manière asynchrone
model
.get(
/.../
)
.then(/.../)
Model
36
3h
@xebiconfr #xebiconfr
Le Modèle optimise les requêtes concurrentes
model
.get(
'posts[0].title',
'posts[1].title',
'posts[0].content',
'posts[1].content,
)
.then(/.../)
// Path envoyé au backend sous form de “query string”
paths:
[["posts",{"from":0,"to":1},["title", “content”]]]
Model
37
3i
@xebiconfr #xebiconfr
Le Modèle optimise les requêtes sortantes grâce au cache
model
.get('posts[0..1].title').then(/.../)
// Path envoyé au backend sous form de “query string”
paths:
[["posts",{"from":0,"to":1},"title"]]
model
.get('posts[0..1][“title”,”content”]').then(/.../)
// Path envoyé au backend est optimisé pour ne chercher que la donnée manquante
paths:
[["posts",{"from":0,"to":1},"content"]]
Model
38
3j
@xebiconfr #xebiconfr
Pour permettre au JSON de passer d’arbre à graph.
Types primitifs supplémentaires :
● Reference (ref) : lien symbolique
● Atom (atom) : valeur json (object / array)
● Error (error) : erreur (surtout utilisé côté routeur)
JSON Graph
39
3k
@xebiconfr #xebiconfr
{
postsByIds: {
1000: {
title: "Aliquip voluptate ",
content: "Ex cupidatat ",
author_id: falcor.Model.ref('usersByIds[1000]')
},
1001: {...}
},
posts: [
{ $type: 'ref', value:['postsByIds', 1000] },
{ $type: 'ref', value:['postsByIds', 1001] }
]
}})
JSON Graph : ref
40
3l
@xebiconfr #xebiconfr
Data Sources
41
3m
Une interface qui permet d’exposer un JSON Graph
Opérations disponibles pour Route ou Model :
● get : lire
● set : modifier
● call : appeler une fonction du graph (non idempotent)
@xebiconfr #xebiconfr
Router
● Pattern matching sur la structure du graph Json.
● Trois types spécifiques :
○ {integers} / {range} / {keys}
● pathSet comprend les arguments du path sous forme d’array
// front
model.get('posts[0].title')
// route
route: "posts[{integers:postId}]['title', 'content']",
get: (pathSet) => {
return someAsyncService.getData(pathSet)
//… pathSet[0] = posts / pathSet[1] = 0 / pathSet[2] = title //
}
42
3n
@xebiconfr #xebiconfr
model.get(
'postsById[12549]["title", "content", "tags", "author"]'
)
model.get(`
authorsById[${data.author.id}]["firstName", "lastName"]
`)
model.get(`
commentsById[${data.comments.from}..${data.comments.to}]
["content", "author"]
`)
model.get(`
authorsById[${data.author.from}..${data.author.to}]
["firstName", "lastName", "count_comments", "count_post"]
`)
La requête pour notre blog
43
3o
GraphQL for iOS par Simone Civetta
GraphQL est une technologie dont vous avez
entendu parler, peut-être, de vos collègues
Front. Il s’agit d’une API middleware, similaire
à un ESB, qui…
Tags: Front, GraphQL, FalcorJS, React
Commentaires
Par Abdelhakim Bachar, Il y a 3 mois
An awesome article
Par Antoine Le Taxin, Il y a 3 mois
Wow.. Thanks much for sharing..
5 articles, 30 commentaires
@xebiconfr #xebiconfr
Take Away
4
44
@xebiconfr #xebiconfr
Avantages / inconvénients de GraphQL
✔ Déclaratif (requête, type)
✔ Documentation vivante
✔ Une seule requête suffit
✔ Exploration facile des données
✔ Contrôle total sur la granularité des informations
✘ Ne supporte ni les opérateurs, ni les fonctions d'agrégation
✘ Pas de gestion automatique du cache
45
4a
@xebiconfr #xebiconfr
Avantages / inconvénients de Falcor
✔ Gestion automatique du cache
✔ Optimisation à la volée des requêtes
✔ Contrôle total sur la granularité des informations
✔ Optimisé pour la gestion de sources de données multiples
✔ Le code front et back utilisent la même librairie
✘ Impératif (pas de type)
✘ Ne supporte ni les opérateurs, ni les fonctions d'agrégation
? Implémentation du backend est laissé à la charge du développeur
46
4b
@xebiconfr #xebiconfr
Cas d’utilisation
Prendre l’une des deux solutions si :
- Beaucoup de lecture, peu d’écriture
- Le réseau et la latence est la principale préoccupation (Mobile)
S’orienter vers GraphQL si :
- Vous voulez une validation du modèle et une documentation
- Vous voulez utiliser autre langage que Javascript
S’orienter vers Falcor si :
- Vos données sont réparties à différents endroits
- Vous voulez un cache géré automatiquement et optimisé
47
4c
@xebiconfr #xebiconfr
Questions ?
Merci !
48
1 sur 48

Recommandé

XebiCon'16 : Choisissez votre style avec Docker & Amazon Web Services Par Al... par
XebiCon'16 : Choisissez votre style avec Docker & Amazon Web Services  Par Al...XebiCon'16 : Choisissez votre style avec Docker & Amazon Web Services  Par Al...
XebiCon'16 : Choisissez votre style avec Docker & Amazon Web Services Par Al...Publicis Sapient Engineering
565 vues62 diapositives
XebiCon'16 : NodeJS x Craftsmanship - Comment faire un projet dans les règles... par
XebiCon'16 : NodeJS x Craftsmanship - Comment faire un projet dans les règles...XebiCon'16 : NodeJS x Craftsmanship - Comment faire un projet dans les règles...
XebiCon'16 : NodeJS x Craftsmanship - Comment faire un projet dans les règles...Publicis Sapient Engineering
480 vues8 diapositives
XebiCon'18 - Architecturer son application mobile pour la durabilité par
XebiCon'18 - Architecturer son application mobile pour la durabilitéXebiCon'18 - Architecturer son application mobile pour la durabilité
XebiCon'18 - Architecturer son application mobile pour la durabilitéPublicis Sapient Engineering
230 vues61 diapositives
XebiCon'16 : Xebia Labs : Les outils de déploiement sont morts avec les Conta... par
XebiCon'16 : Xebia Labs : Les outils de déploiement sont morts avec les Conta...XebiCon'16 : Xebia Labs : Les outils de déploiement sont morts avec les Conta...
XebiCon'16 : Xebia Labs : Les outils de déploiement sont morts avec les Conta...Publicis Sapient Engineering
650 vues20 diapositives
XebiCon'16 : Data Science & Craftsmanship : Je t'aime, moi non plus. Par Yoan... par
XebiCon'16 : Data Science & Craftsmanship : Je t'aime, moi non plus. Par Yoan...XebiCon'16 : Data Science & Craftsmanship : Je t'aime, moi non plus. Par Yoan...
XebiCon'16 : Data Science & Craftsmanship : Je t'aime, moi non plus. Par Yoan...Publicis Sapient Engineering
669 vues61 diapositives
XebiCon'18 - Deno, le nouveau NodeJS qui inverse la tendance ? par
XebiCon'18 - Deno, le nouveau NodeJS qui inverse la tendance ?XebiCon'18 - Deno, le nouveau NodeJS qui inverse la tendance ?
XebiCon'18 - Deno, le nouveau NodeJS qui inverse la tendance ?Publicis Sapient Engineering
565 vues25 diapositives

Contenu connexe

Tendances

XebiCon'18 - Comment j'ai développé un jeu vidéo avec des outils de développe... par
XebiCon'18 - Comment j'ai développé un jeu vidéo avec des outils de développe...XebiCon'18 - Comment j'ai développé un jeu vidéo avec des outils de développe...
XebiCon'18 - Comment j'ai développé un jeu vidéo avec des outils de développe...Publicis Sapient Engineering
323 vues67 diapositives
XebiCon'16 : Orange - Transformation DevOps, les conteneurs sont vos alliés ! par
XebiCon'16 : Orange - Transformation DevOps, les conteneurs sont vos alliés !XebiCon'16 : Orange - Transformation DevOps, les conteneurs sont vos alliés !
XebiCon'16 : Orange - Transformation DevOps, les conteneurs sont vos alliés !Publicis Sapient Engineering
1.3K vues83 diapositives
XebiCon'16 : La programmation concurrente en Go. Par Jérome Doucet et Diana O... par
XebiCon'16 : La programmation concurrente en Go. Par Jérome Doucet et Diana O...XebiCon'16 : La programmation concurrente en Go. Par Jérome Doucet et Diana O...
XebiCon'16 : La programmation concurrente en Go. Par Jérome Doucet et Diana O...Publicis Sapient Engineering
568 vues26 diapositives
XebiCon'18 - La sécurité, douce illusion même en 2018 par
XebiCon'18 - La sécurité, douce illusion même en 2018XebiCon'18 - La sécurité, douce illusion même en 2018
XebiCon'18 - La sécurité, douce illusion même en 2018Publicis Sapient Engineering
268 vues22 diapositives
XebiCon'16 : Le futur de la télévision, les applications ! Par Fabien Mirault... par
XebiCon'16 : Le futur de la télévision, les applications ! Par Fabien Mirault...XebiCon'16 : Le futur de la télévision, les applications ! Par Fabien Mirault...
XebiCon'16 : Le futur de la télévision, les applications ! Par Fabien Mirault...Publicis Sapient Engineering
656 vues92 diapositives
XebiCon'18 - Les utilisateurs finaux, les oubliés de nos produits ! par
XebiCon'18 - Les utilisateurs finaux, les oubliés de nos produits !XebiCon'18 - Les utilisateurs finaux, les oubliés de nos produits !
XebiCon'18 - Les utilisateurs finaux, les oubliés de nos produits !Publicis Sapient Engineering
338 vues23 diapositives

Tendances(20)

Xebicon2016 - React Native & Redux par pgdejardin
Xebicon2016 - React Native & ReduxXebicon2016 - React Native & Redux
Xebicon2016 - React Native & Redux
pgdejardin308 vues
Monitoring de conteneurs en production - Jonathan Raffre & Jean-Pascal Thiery par Paris Container Day
Monitoring de conteneurs en production - Jonathan Raffre & Jean-Pascal ThieryMonitoring de conteneurs en production - Jonathan Raffre & Jean-Pascal Thiery
Monitoring de conteneurs en production - Jonathan Raffre & Jean-Pascal Thiery
OVHcloud Tech-Talk S01E04 - La télémétrie au service de l'agilité par OVHcloud
OVHcloud Tech-Talk S01E04 - La télémétrie au service de l'agilitéOVHcloud Tech-Talk S01E04 - La télémétrie au service de l'agilité
OVHcloud Tech-Talk S01E04 - La télémétrie au service de l'agilité
OVHcloud329 vues
Développement : mettez le turbo ! - Liferay France Symposium 2017 par Sébastien Le Marchand
Développement : mettez le turbo ! - Liferay France Symposium 2017Développement : mettez le turbo ! - Liferay France Symposium 2017
Développement : mettez le turbo ! - Liferay France Symposium 2017

En vedette

API design principles for accelerated development par
API design principles for accelerated developmentAPI design principles for accelerated development
API design principles for accelerated developmentJonathan LeBlanc
3.9K vues41 diapositives
Take Control of your APIs in a Microservice Architecture par
Take Control of your APIs in a Microservice ArchitectureTake Control of your APIs in a Microservice Architecture
Take Control of your APIs in a Microservice Architecture3scale
3.1K vues17 diapositives
How to use Donuts and Onions for Scaling API Programs par
How to use Donuts and Onions for Scaling API ProgramsHow to use Donuts and Onions for Scaling API Programs
How to use Donuts and Onions for Scaling API Programs3scale
7.9K vues23 diapositives
APIS for Startups - Running your Business Inside Out par
APIS for Startups - Running your Business Inside OutAPIS for Startups - Running your Business Inside Out
APIS for Startups - Running your Business Inside Out3scale
6.5K vues63 diapositives
Oracle api gateway overview par
Oracle api gateway overviewOracle api gateway overview
Oracle api gateway overviewOracle Corporation
4.3K vues14 diapositives
API Management architect presentation par
API Management architect presentationAPI Management architect presentation
API Management architect presentationsflynn073
13.6K vues98 diapositives

En vedette(10)

API design principles for accelerated development par Jonathan LeBlanc
API design principles for accelerated developmentAPI design principles for accelerated development
API design principles for accelerated development
Jonathan LeBlanc3.9K vues
Take Control of your APIs in a Microservice Architecture par 3scale
Take Control of your APIs in a Microservice ArchitectureTake Control of your APIs in a Microservice Architecture
Take Control of your APIs in a Microservice Architecture
3scale3.1K vues
How to use Donuts and Onions for Scaling API Programs par 3scale
How to use Donuts and Onions for Scaling API ProgramsHow to use Donuts and Onions for Scaling API Programs
How to use Donuts and Onions for Scaling API Programs
3scale7.9K vues
APIS for Startups - Running your Business Inside Out par 3scale
APIS for Startups - Running your Business Inside OutAPIS for Startups - Running your Business Inside Out
APIS for Startups - Running your Business Inside Out
3scale6.5K vues
API Management architect presentation par sflynn073
API Management architect presentationAPI Management architect presentation
API Management architect presentation
sflynn07313.6K vues
Integrating, exposing and managing distributed data with RESTful APIs and op... par 3scale
Integrating, exposing and managing distributed data with RESTful APIs and op...Integrating, exposing and managing distributed data with RESTful APIs and op...
Integrating, exposing and managing distributed data with RESTful APIs and op...
3scale5.3K vues
The Fundamentals of Platform Strategy: Creating Genuine Value with APIs par 3scale
The Fundamentals of Platform Strategy: Creating Genuine Value with APIsThe Fundamentals of Platform Strategy: Creating Genuine Value with APIs
The Fundamentals of Platform Strategy: Creating Genuine Value with APIs
3scale2.3K vues
Test and Protect Your API par SmartBear
Test and Protect Your APITest and Protect Your API
Test and Protect Your API
SmartBear1.8K vues
The API-Application Semantic Gap par 3scale
The API-Application Semantic GapThe API-Application Semantic Gap
The API-Application Semantic Gap
3scale3.2K vues

Similaire à XebiCon'16 : GraphQL et Falcor, un nouveau regard sur les architectures REST ? Par Antoine Le Taxin et Abdelhakim Bachar, Développeurs Front-End chez Xebia

Refcard GraphQL par
Refcard GraphQLRefcard GraphQL
Refcard GraphQLOCTO Technology
19 vues14 diapositives
Introduction aux RIA (Rich Internet Applications) par
Introduction aux RIA (Rich Internet Applications)Introduction aux RIA (Rich Internet Applications)
Introduction aux RIA (Rich Internet Applications)Tugdual Grall
3.6K vues84 diapositives
Codedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript par
Codedarmor 2012 - 06/03 - HTML5, CSS3 et JavascriptCodedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript
Codedarmor 2012 - 06/03 - HTML5, CSS3 et Javascriptcodedarmor
1.9K vues41 diapositives
Développer sereinement avec Node.js par
Développer sereinement avec Node.jsDévelopper sereinement avec Node.js
Développer sereinement avec Node.jsJulien Giovaresco
146 vues78 diapositives
Big Data Viz (and much more!) with Apache Zeppelin par
Big Data Viz (and much more!) with Apache ZeppelinBig Data Viz (and much more!) with Apache Zeppelin
Big Data Viz (and much more!) with Apache ZeppelinBruno Bonnin
1.2K vues23 diapositives
Grails from scratch to prod - MixIT 2011 par
Grails from scratch to prod - MixIT 2011Grails from scratch to prod - MixIT 2011
Grails from scratch to prod - MixIT 2011Aurélien Maury
664 vues46 diapositives

Similaire à XebiCon'16 : GraphQL et Falcor, un nouveau regard sur les architectures REST ? Par Antoine Le Taxin et Abdelhakim Bachar, Développeurs Front-End chez Xebia(20)

Introduction aux RIA (Rich Internet Applications) par Tugdual Grall
Introduction aux RIA (Rich Internet Applications)Introduction aux RIA (Rich Internet Applications)
Introduction aux RIA (Rich Internet Applications)
Tugdual Grall3.6K vues
Codedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript par codedarmor
Codedarmor 2012 - 06/03 - HTML5, CSS3 et JavascriptCodedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript
Codedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript
codedarmor1.9K vues
Big Data Viz (and much more!) with Apache Zeppelin par Bruno Bonnin
Big Data Viz (and much more!) with Apache ZeppelinBig Data Viz (and much more!) with Apache Zeppelin
Big Data Viz (and much more!) with Apache Zeppelin
Bruno Bonnin1.2K vues
Grails from scratch to prod - MixIT 2011 par Aurélien Maury
Grails from scratch to prod - MixIT 2011Grails from scratch to prod - MixIT 2011
Grails from scratch to prod - MixIT 2011
Aurélien Maury664 vues
De Java à Kotlin - L'histoire d'une migration par Robin Penea
De Java à Kotlin - L'histoire d'une migrationDe Java à Kotlin - L'histoire d'une migration
De Java à Kotlin - L'histoire d'une migration
Robin Penea89 vues
Introduction à Angularjs par Rossi Oddet
Introduction à AngularjsIntroduction à Angularjs
Introduction à Angularjs
Rossi Oddet1.6K vues
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017) par univalence
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017) Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017)
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017)
univalence 1.3K vues
Room ou Realm : Quelle base de données pour vos applications Android ? par Ludovic ROLAND
Room ou Realm : Quelle base de données pour vos applications Android ?Room ou Realm : Quelle base de données pour vos applications Android ?
Room ou Realm : Quelle base de données pour vos applications Android ?
Ludovic ROLAND1.7K vues
Flex, une techno RIA incontournable pour les futures app web ? par GreenIvory
Flex, une techno RIA incontournable pour les futures app web ?Flex, une techno RIA incontournable pour les futures app web ?
Flex, une techno RIA incontournable pour les futures app web ?
GreenIvory1.8K vues
2014 03-12-fr schema design and app architecture-2 par MongoDB
2014 03-12-fr schema design and app architecture-22014 03-12-fr schema design and app architecture-2
2014 03-12-fr schema design and app architecture-2
MongoDB1.8K vues
Hands on lab Elasticsearch par David Pilato
Hands on lab ElasticsearchHands on lab Elasticsearch
Hands on lab Elasticsearch
David Pilato6.2K vues
Les concepts de la programmation fonctionnelle illustrés avec java 8 par Yannick Chartois
Les concepts de la programmation fonctionnelle illustrés avec java 8Les concepts de la programmation fonctionnelle illustrés avec java 8
Les concepts de la programmation fonctionnelle illustrés avec java 8
Yannick Chartois1.8K vues

Plus de Publicis Sapient Engineering

XebiCon'18 - L'algorithme de reconnaissance de formes par le cerveau humain par
XebiCon'18 - L'algorithme de reconnaissance de formes par le cerveau humainXebiCon'18 - L'algorithme de reconnaissance de formes par le cerveau humain
XebiCon'18 - L'algorithme de reconnaissance de formes par le cerveau humainPublicis Sapient Engineering
1.7K vues51 diapositives
Xebicon'18 - IoT: From Edge to Cloud par
Xebicon'18 - IoT: From Edge to CloudXebicon'18 - IoT: From Edge to Cloud
Xebicon'18 - IoT: From Edge to CloudPublicis Sapient Engineering
627 vues46 diapositives
XebiCon'18 - Modern Infrastructure par
XebiCon'18 - Modern InfrastructureXebiCon'18 - Modern Infrastructure
XebiCon'18 - Modern InfrastructurePublicis Sapient Engineering
541 vues90 diapositives
XebiCon'18 - La Web App d'aujourd'hui et de demain : état de l'art et bleedin... par
XebiCon'18 - La Web App d'aujourd'hui et de demain : état de l'art et bleedin...XebiCon'18 - La Web App d'aujourd'hui et de demain : état de l'art et bleedin...
XebiCon'18 - La Web App d'aujourd'hui et de demain : état de l'art et bleedin...Publicis Sapient Engineering
580 vues61 diapositives
XebiCon'18 - Des notebook pour le monitoring avec Zeppelin par
XebiCon'18 - Des notebook pour le monitoring avec Zeppelin XebiCon'18 - Des notebook pour le monitoring avec Zeppelin
XebiCon'18 - Des notebook pour le monitoring avec Zeppelin Publicis Sapient Engineering
457 vues23 diapositives
XebiCon'18 - Event Sourcing et RGPD, incompatibles ? par
XebiCon'18 - Event Sourcing et RGPD, incompatibles ?XebiCon'18 - Event Sourcing et RGPD, incompatibles ?
XebiCon'18 - Event Sourcing et RGPD, incompatibles ?Publicis Sapient Engineering
809 vues35 diapositives

Plus de Publicis Sapient Engineering(20)

XebiCon'16 : GraphQL et Falcor, un nouveau regard sur les architectures REST ? Par Antoine Le Taxin et Abdelhakim Bachar, Développeurs Front-End chez Xebia

  • 1. @xebiconfr #xebiconfr GraphQL et Falcor, un nouveau regard sur les architectures REST Abdelhakim Bachar Antoine Le Taxin
  • 2. @xebiconfr #xebiconfr Qui sommes-nous ? Abdelhakim Bachar @a_bachar 2 Antoine Le Taxin @modulom
  • 3. @xebiconfr #xebiconfr Super, un nouveau projet ! 1 3
  • 4. @xebiconfr #xebiconfr Besoin GraphQL for iOS par Simone Civetta GraphQL est une technologie dont vous avez entendu parler, peut-être, de vos collègues Front. Il s’agit d’une API middleware, similaire à un ESB, qui… Tags: Front, GraphQL, FalcorJS, React Commentaires Par Abdelhakim Bachar, Il y a 3 mois An awesome article Par Antoine Le Taxin, Il y a 3 mois Wow.. Thanks much for sharing.. 4 1a 5 articles, 30 commentaires
  • 5. @xebiconfr #xebiconfr RESTful (representational state transfer) ✔ Possibilité de cache ✔ Indépendance entre le modèle et la vue 5 1b { "id": 1, "title": "Lorem ipsum", "authorId": 1000 } { "id": 1000, "lastName": "Carver", "firstName": "Kerry" } ✘ Latence (grand nombre de requêtes ou réponse lourde) ✘ Over fetching [GET]/post/1 [GET]/user/1000
  • 7. @xebiconfr #xebiconfr Qu’est ce que GraphQL ? ● Est une Spécification ● Implémentée en plusieurs langages de programmation ● Définit un langage permettant de requêter et récupérer de manière déclarative des données depuis un back-end 7 2a
  • 8. @xebiconfr #xebiconfr Trois points d’histoire ● Créé par Facebook ● Remplacer tous les services REST nécessaires aux applications mobile ● En production depuis 2012 pour les applications iOS et Android de Facebook 8 2b
  • 9. @xebiconfr #xebiconfr Objectif Avoir un outil puissant, productif et rétrocompatible pour développer des applications 9 2c
  • 10. @xebiconfr #xebiconfr A quoi ressemble une requête ? 10 2d // Résultat { "user": { "id": 123456 "name": "Abdelhakim B." } } // Requête GraphQL { user(id: 123456) { id name } }
  • 11. @xebiconfr #xebiconfr Les Concepts de Base ● Hiérarchique ● Requêtes spécifiques au client ● Typage fort ● Rétrocompatibilité ● Introspectif ● Indépendant du transport 11 2e
  • 13. @xebiconfr #xebiconfr Requêtes spécifiques au client 13 2g Serveur Possibilités Client Besoins
  • 14. @xebiconfr #xebiconfr const UserType = new GraphQLObjectType({ name: 'User', description: 'Define a user resource', fields: () => ({ firstName: { type: GraphQLString, resolve: tag => tag.label }, posts: { type: new GraphQLList(PostType), resolve: tag => tag.getPosts() } }) }); Typage fort 14 2h
  • 15. @xebiconfr #xebiconfr const UserType = new GraphQLObjectType({ fields: () => ({ fullName: { type: GraphQLString, isDeprecated: true, deprecationReason: "You don't need it", resolve: user => `${user.firstName} ${user.lastName}` } }) }); Rétrocompatibilité 15 2i
  • 16. @xebiconfr #xebiconfr Introspectif 16 2j { __type(name: "User") { name kind } } { "data": { "__type": { "name": "User", "kind": "OBJECT" } } }
  • 18. @xebiconfr #xebiconfr Indépendant du transport 18 2l WebSocket
  • 19. @xebiconfr #xebiconfr Que des requêtes ? Non, pas seulement les requêtes, mais aussi la création, la mis à jour et la suppression grâce au Mutation 19 2m
  • 20. @xebiconfr #xebiconfr Comment requêter un serveur GraphQL ? POST curl -XPOST -d 'query { user { name } }' http://localhost:3000 GET http://localhost:3000/graphql?query={user{name}} 20 2n
  • 21. @xebiconfr #xebiconfr app.use('/graphql', expressGraphql({ schema, pretty: true, graphiql: true })); GraphQL HTTP Server Middleware 21 2o
  • 22. @xebiconfr #xebiconfr const schema = new GraphQLSchema({ query: queryType, mutation: mutationType }); GraphQL Schema 22 2p
  • 23. @xebiconfr #xebiconfr const queryType = new GraphQLObjectType({ name: 'Query', description: 'Root query entry point', fields: () => ({ users: UserQuery, posts: PostQuery, // ... }) }); GraphQL Query 23 2q
  • 24. @xebiconfr #xebiconfr const UserQuery = { type: new GraphQLList(UserType), args: { id: { type: GraphQLInt }, firstName: { type: GraphQLString }, // ... }, resolve: (root, args) => User.findAll({where: args}) }; UserQuery 24 2s
  • 25. @xebiconfr #xebiconfr const UserType = GraphQLObjectType({ name: 'User', description: 'Blog user', fields: () => ({ id: { type: GraphQLInt, resolve: u => u.id }, firstName: { type: GraphQLString }, posts: { type: new GraphQLList(PostType), resolve: u => u.getPosts() } }) }); Type User 25 2t
  • 26. @xebiconfr #xebiconfr const mutationType = new GraphQLObjectType({ name: "Mutation", description: "Root mutation entry point", fields: () => ({ createUser: { type: UserType, args: { firstName: {type: new GraphQLNonNull(GraphQLString)} }, resolve: (source, args) => User.create(Object.assign({}, args)) } }) }); GraphQL Mutation 26 2r
  • 27. @xebiconfr #xebiconfr { posts(name: 12549) { id title content author { id firstName lastName } comments { content author { id firstName lastName count_comments count_posts } } } } La requête pour notre blog 27 2u GraphQL for iOS par Simone Civetta GraphQL est une technologie dont vous avez entendu parler, peut-être, de vos collègues Front. Il s’agit d’une API middleware, similaire à un ESB, qui… Tags: Front, GraphQL, FalcorJS, React Commentaires Par Abdelhakim Bachar, Il y a 3 mois An awesome article Par Antoine Le Taxin, Il y a 3 mois Wow.. Thanks much for sharing.. 5 articles, 30 commentaires
  • 29. @xebiconfr #xebiconfr ● Est un librairie Javascript open source ● Propose une manière impérative de décrire et d’accéder aux données ● Embarque un système de cache et d’optimisation de requêtes Qu’est ce que Falcor ? 29 3a
  • 30. @xebiconfr #xebiconfr ● Créé par Netflix ● Répond aux besoins de performance, d’éclatement de leur sources de données et diversité des supports ● En production pour leur applications TV, mobile et desktop et open source depuis 2015 Trois points d’histoire 30 3b
  • 31. @xebiconfr #xebiconfr Avoir un outil centré sur la performance et le cloud, spécialement adapté aux architectures microservices. Objectif 31 3c
  • 32. @xebiconfr #xebiconfr A quoi ressemble une requête ? 32 3d // Résultat { "user": { "name": "Abdelhakim B." } } // Requête falcor model .get('users[0].name') .then( // )
  • 33. @xebiconfr #xebiconfr Les Concepts de Base 33 3e Paths JSON Graph Data SourcesRouter Model
  • 34. @xebiconfr #xebiconfr ● Langage de query de Falcor ● Exprime un chemin au travers d’un objet JSON ● Il accepte deux syntaxes : ○ Syntaxe Path String ○ Array de clés 'posts[1].title' ['posts', 1, 'title'] 'posts[1..2]['title','content']' ['posts', {from: 1, to: 2}, ['title','content']] Paths 34 3f
  • 35. @xebiconfr #xebiconfr ● On accède aux données au travers d’un graph JSON unique (quelque soit le nombre de sources) // frontend var model = new falcor.Model({ source: new falcor.HttpDataSource('api/model.json') }) // backend app.use('/api/model.json', falcorExpress.dataSourceRoute((req, res) => { return new Router([ (...) ]) } ) Model 35 3g
  • 36. @xebiconfr #xebiconfr ● Retourne les données de manière asynchrone model .get( /.../ ) .then(/.../) Model 36 3h
  • 37. @xebiconfr #xebiconfr Le Modèle optimise les requêtes concurrentes model .get( 'posts[0].title', 'posts[1].title', 'posts[0].content', 'posts[1].content, ) .then(/.../) // Path envoyé au backend sous form de “query string” paths: [["posts",{"from":0,"to":1},["title", “content”]]] Model 37 3i
  • 38. @xebiconfr #xebiconfr Le Modèle optimise les requêtes sortantes grâce au cache model .get('posts[0..1].title').then(/.../) // Path envoyé au backend sous form de “query string” paths: [["posts",{"from":0,"to":1},"title"]] model .get('posts[0..1][“title”,”content”]').then(/.../) // Path envoyé au backend est optimisé pour ne chercher que la donnée manquante paths: [["posts",{"from":0,"to":1},"content"]] Model 38 3j
  • 39. @xebiconfr #xebiconfr Pour permettre au JSON de passer d’arbre à graph. Types primitifs supplémentaires : ● Reference (ref) : lien symbolique ● Atom (atom) : valeur json (object / array) ● Error (error) : erreur (surtout utilisé côté routeur) JSON Graph 39 3k
  • 40. @xebiconfr #xebiconfr { postsByIds: { 1000: { title: "Aliquip voluptate ", content: "Ex cupidatat ", author_id: falcor.Model.ref('usersByIds[1000]') }, 1001: {...} }, posts: [ { $type: 'ref', value:['postsByIds', 1000] }, { $type: 'ref', value:['postsByIds', 1001] } ] }}) JSON Graph : ref 40 3l
  • 41. @xebiconfr #xebiconfr Data Sources 41 3m Une interface qui permet d’exposer un JSON Graph Opérations disponibles pour Route ou Model : ● get : lire ● set : modifier ● call : appeler une fonction du graph (non idempotent)
  • 42. @xebiconfr #xebiconfr Router ● Pattern matching sur la structure du graph Json. ● Trois types spécifiques : ○ {integers} / {range} / {keys} ● pathSet comprend les arguments du path sous forme d’array // front model.get('posts[0].title') // route route: "posts[{integers:postId}]['title', 'content']", get: (pathSet) => { return someAsyncService.getData(pathSet) //… pathSet[0] = posts / pathSet[1] = 0 / pathSet[2] = title // } 42 3n
  • 43. @xebiconfr #xebiconfr model.get( 'postsById[12549]["title", "content", "tags", "author"]' ) model.get(` authorsById[${data.author.id}]["firstName", "lastName"] `) model.get(` commentsById[${data.comments.from}..${data.comments.to}] ["content", "author"] `) model.get(` authorsById[${data.author.from}..${data.author.to}] ["firstName", "lastName", "count_comments", "count_post"] `) La requête pour notre blog 43 3o GraphQL for iOS par Simone Civetta GraphQL est une technologie dont vous avez entendu parler, peut-être, de vos collègues Front. Il s’agit d’une API middleware, similaire à un ESB, qui… Tags: Front, GraphQL, FalcorJS, React Commentaires Par Abdelhakim Bachar, Il y a 3 mois An awesome article Par Antoine Le Taxin, Il y a 3 mois Wow.. Thanks much for sharing.. 5 articles, 30 commentaires
  • 45. @xebiconfr #xebiconfr Avantages / inconvénients de GraphQL ✔ Déclaratif (requête, type) ✔ Documentation vivante ✔ Une seule requête suffit ✔ Exploration facile des données ✔ Contrôle total sur la granularité des informations ✘ Ne supporte ni les opérateurs, ni les fonctions d'agrégation ✘ Pas de gestion automatique du cache 45 4a
  • 46. @xebiconfr #xebiconfr Avantages / inconvénients de Falcor ✔ Gestion automatique du cache ✔ Optimisation à la volée des requêtes ✔ Contrôle total sur la granularité des informations ✔ Optimisé pour la gestion de sources de données multiples ✔ Le code front et back utilisent la même librairie ✘ Impératif (pas de type) ✘ Ne supporte ni les opérateurs, ni les fonctions d'agrégation ? Implémentation du backend est laissé à la charge du développeur 46 4b
  • 47. @xebiconfr #xebiconfr Cas d’utilisation Prendre l’une des deux solutions si : - Beaucoup de lecture, peu d’écriture - Le réseau et la latence est la principale préoccupation (Mobile) S’orienter vers GraphQL si : - Vous voulez une validation du modèle et une documentation - Vous voulez utiliser autre langage que Javascript S’orienter vers Falcor si : - Vos données sont réparties à différents endroits - Vous voulez un cache géré automatiquement et optimisé 47 4c