Cyril Moreau
Ingénieur Front-end @dailymotion. Participant fréquent à @MarseilleJS
10 avril 2018 - @MarseilleJS
Espace Partenaire Dailymotion
- Toujours présent
- 3 milliards de vidéos vues / mois
- 137 millions de vis. uniques / mois
Millennium Falcon
Exemple : Fiche vaisseau Star Wars
Apparaît dans les films :
The Force Awakens
Return of the Jedi
The Empire Strikes Back
A New Hope
Trois derniers pilotes :
Lando Calrissian
Nien Nunb
Rey
{
"name": "Millennium Falcon",
"id": "cj0nwtqpzq4tt01142nh7e9i4",
"cargoCapacity": 100000,
"consumables": "2 months",
"crew": "4",
"length": 34.37,
"manufacturer": "Corellian Engineering Corporation"
}GET
/starships/<id>
/starships/<id>/films
/starships/<id>/pilots[
{
"releaseDate": "2015-12-11T00:00:00.000Z",
"isPublished": true,
"director": "J. J. Abrams",
"episodeId": 7,
"title": "The Force Awakens",
"openingCrawl": "Luke Skywalker has vanished.\r\nIn his absence, the sinister\r\nFIRST ORDER has risen from\r\nthe ashes of the Empire\r\nand will not rest until\r\nSkywalker, the last Jedi,\r\nhas been destroyed.\r\n \r\nWith the support of the\r\nREPUBLIC, General Leia Organa\r\nleads a brave RESISTANCE.\r\nShe is desperate to find her\r\nbrother Luke and gain his\r\nhelp in restoring peace and\r\njustice to the galaxy.\r\n \r\nLeia has sent her most daring\r\npilot on a secret mission\r\nto Jakku, where an old ally\r\nhas discovered a clue to\r\nLuke's whereabouts...."
},
{
"releaseDate": "1983-05-25T00:00:00.000Z",
"isPublished": true,
"director": "Richard Marquand",
"episodeId": 6,
"title": "Return of the Jedi",
"openingCrawl": "Luke Skywalker has returned to\r\nhis home planet of Tatooine in\r\nan attempt to rescue his\r\nfriend Han Solo from the\r\nclutches of the vile gangster\r\nJabba the Hutt.\r\n\r\nLittle does Luke know that the\r\nGALACTIC EMPIRE has secretly\r\nbegun construction on a new\r\narmored space station even\r\nmore powerful than the first\r\ndreaded Death Star.\r\n\r\nWhen completed, this ultimate\r\nweapon will spell certain doom\r\nfor the small band of rebels\r\nstruggling to restore freedom\r\nto the galaxy..."
},
{
"releaseDate": "1980-05-17T00:00:00.000Z",
"isPublished": true,
"director": "Irvin Kershner",
"episodeId": 5,
"title": "The Empire Strikes Back",
"openingCrawl": "It is a dark time for the\r\nRebellion. Although the Death\r\nStar has been destroyed,\r\nImperial troops have driven the\r\nRebel forces from their hidden\r\nbase and pursued them across\r\nthe galaxy.\r\n\r\nEvading the dreaded Imperial\r\nStarfleet, a group of freedom\r\nfighters led by Luke Skywalker\r\nhas established a new secret\r\nbase on the remote ice world\r\nof Hoth.\r\n\r\nThe evil lord Darth Vader,\r\nobsessed with finding young\r\nSkywalker, has dispatched\r\nthousands of remote probes into\r\nthe far reaches of space...."
},
{
"releaseDate": "1977-05-25T00:00:00.000Z",
"isPublished": true,
"director": "George Lucas",
"episodeId": 4,
"title": "A New Hope",
"openingCrawl": "It is a period of civil war.\r\nRebel spaceships, striking\r\nfrom a hidden base, have won\r\ntheir first victory against\r\nthe evil Galactic Empire.\r\n\r\nDuring the battle, Rebel\r\nspies managed to steal secret\r\nplans to the Empire's\r\nultimate weapon, the DEATH\r\nSTAR, an armored space\r\nstation with enough power\r\nto destroy an entire planet.\r\n\r\nPursued by the Empire's\r\nsinister agents, Princess\r\nLeia races home aboard her\r\nstarship, custodian of the\r\nstolen plans that can save her\r\npeople and restore\r\nfreedom to the galaxy...."
}
]{
"name": "Lando Calrissian",
"hairColor": [
"BLACK"
],
"birthYear": "31BBY",
"createdAt": "2017-03-24T13:32:40.000Z",
"eyeColor": [
"BROWN"
],
"gender": "MALE"
},
{
"name": "Nien Nunb",
"hairColor": null,
"birthYear": null,
"createdAt": "2017-03-24T13:32:40.000Z",
"eyeColor": [
"BLACK"
],
"gender": "MALE"
},
{
"name": "Rey",
"hairColor": [
"BROWN"
],
"birthYear": null,
"createdAt": "2017-03-24T13:32:41.000Z",
"eyeColor": [
"HAZEL"
],
"gender": "FEMALE"
}{
Starship(id: "cj0nwtqpzq4tt01142nh7e9i4") {
name
films(orderBy: releaseDate_DESC) {
title
}
pilots(last: 3) {
name
}
}
}{
"data": {
"Starship": {
"name": "Millennium Falcon",
"id": "cj0nwtqpzq4tt01142nh7e9i4",
"films": [
{
"title": "The Force Awakens"
},
{
"title": "Return of the Jedi"
},
{
"title": "The Empire Strikes Back"
},
{
"title": "A New Hope"
}
],
"pilots": [
{
"name": "Lando Calrissian"
},
{
"name": "Nien Nunb"
},
{
"name": "Rey"
}
]
}
}
}- autant de endpoints que de ressources :
=> underfetching (pas assez de données renvoyées donc multiplication des requêtes)
- retour rigide :
=> le serveur décide des données retournées
=> overfetching (télécharge des données souvent non nécessaires)
- 1 seul endoint
=> multiples "Query",
- retour souple :
=> le consommateur de l'API décide des données retournées
Impératif
1. Construire la requête HTTP (GET, POST, etc)
2. Recevoir et Parser la réponse
3. Stocker les données quelque part
4. Afficher l'information dans l'UI
Déclaratif
1. Décrire les données nécessaires
Construire la requête HTTP (GET, POST, etc)
2. Recevoir et Parser la réponse
3. Stocker les données quelque part
4. Afficher l'information sur l'UI
Abstraction par Apollo / Relay
- Caching (adieu Redux, Hello apollo-link-state)
- Optimistic UI (pattern où t'updates l'UI avant d'avoir la réponse du serveur)
- Support des Subscription (permet d'ouvrir un flux client <> serveur et reçoit les modifications en direct si nouveau contenu)
react-apollo : Utiliser Apollo avec React
graphql : Facebook implémentation de GraphQL
Avant :
apollo-client-preset : ajoute apollo-client, apollo-cache-inmemory, apollo-link, apollo-link-http
graphql-tag : GraphQL parser
Maintenant
apollo-boost : remplace apollo-client, apollo-cache-inmemory, apollo-link, apollo-link-http
Pour aller plus loin :
apollo-link-rest : Fallback API REST
GraphQL Playground (Démo Star Wars)
graphcool BaaS
By Cyril Moreau
@MarseilleJS