Successfully reported this slideshow.
Your SlideShare is downloading. ×

GraphQL - Where are you from? Where are you going?

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 30 Ad

GraphQL - Where are you from? Where are you going?

Download to read offline

GraphQL, inventato da Facebook per risolvere un problema molto specifico, è diventato uno standard. Le applicazioni client lo utilizzano per leggere e manipolare i dati esposti dai server back-end. È così flessibile che recentemente GitHub l'ha adottata per tutte le sue API. Il paradigma è semplice e tuttavia potente tale da consentire la manipolazione flessibile e la loro composizione da molte fonti diverse. Mauro offre in questo intervento un'introduzione a GraphQL, partendo da una breve storia e poi analizzando come GraphQL risolva i tipici problemi in cui i progettisti API e i loro consumer si possono imbattere.

GraphQL, inventato da Facebook per risolvere un problema molto specifico, è diventato uno standard. Le applicazioni client lo utilizzano per leggere e manipolare i dati esposti dai server back-end. È così flessibile che recentemente GitHub l'ha adottata per tutte le sue API. Il paradigma è semplice e tuttavia potente tale da consentire la manipolazione flessibile e la loro composizione da molte fonti diverse. Mauro offre in questo intervento un'introduzione a GraphQL, partendo da una breve storia e poi analizzando come GraphQL risolva i tipici problemi in cui i progettisti API e i loro consumer si possono imbattere.

Advertisement
Advertisement

More Related Content

Similar to GraphQL - Where are you from? Where are you going? (20)

More from Mauro Servienti (20)

Advertisement

Recently uploaded (20)

GraphQL - Where are you from? Where are you going?

  1. 1. @mauroservienti#webappconf17 GraphQL Where are you from? Where are you going? (1 fiorino, cit.)
  2. 2. @mauroservienti#webappconf17 we have no control over
  3. 3. @mauroservienti#webappconf17 We go on thinking to… 1. APIs to represent requests and actions 2. Models exchanged with clients
  4. 4. @mauroservienti#webappconf17 API (e.g. Rest over HTTP) Response Request Model Client Hard to evolve monolith(s)
  5. 5. @mauroservienti#webappconf17 Rest + HTTP semantic is not good enough
  6. 6. @mauroservienti#webappconf17 Let me introduce you GraphQL
  7. 7. @mauroservienti#webappconf17 Describe
  8. 8. @mauroservienti#webappconf17 Describe type Product { id: string, title: string, description: string, unitPrice: price, delivery: deliveryEnum, weight: float, stars: float, reviews: [{ title: string, quality: sentimentEnum, text: string, }] }
  9. 9. @mauroservienti#webappconf17 Describe type Product { id: string, title: string, description: string, unitPrice: price, delivery: deliveryEnum, weight: float, stars: float, reviews: [{ title: string, quality: sentimentEnum, text: string, }] }
  10. 10. @mauroservienti#webappconf17 Describe type Product { id: string, title: string, description: string, unitPrice: price, delivery: deliveryEnum, weight: float, stars: float, reviews: [{ title: string, quality: sentimentEnum, text: string, }] }
  11. 11. @mauroservienti#webappconf17 Describe type Product { id: string, title: string, description: string, unitPrice: price, delivery: deliveryEnum, weight: float, stars: float, reviews: [{ title: string, quality: sentimentEnum, text: string, }] }
  12. 12. @mauroservienti#webappconf17 Describe type Product { id: string, title: string, description: string, unitPrice: price, delivery: deliveryEnum, weight: float, stars: float, reviews: [{ title: string, quality: sentimentEnum, text: string, }] }
  13. 13. @mauroservienti#webappconf17 Ask
  14. 14. @mauroservienti#webappconf17 Ask { product( id: 123 ), title, unitPrice: { value, currency }, stars, bestReview: reviews( quality: best ){ title }, worstReview: reviews( quality: worst ){ title } }
  15. 15. @mauroservienti#webappconf17 Ask { product( id: 123 ), title, unitPrice: { value, currency }, stars, bestReview: reviews( quality: best ){ title }, worstReview: reviews( quality: worst ){ title } }
  16. 16. @mauroservienti#webappconf17 Ask { product( id: 123 ), title, unitPrice: { value, currency }, stars, bestReview: reviews( quality: best ){ title }, worstReview: reviews( quality: worst ){ title } }
  17. 17. @mauroservienti#webappconf17 Use { id: 123, title: ‘portabanana’, unitPrice: { 10, Euro }, stars: 3.8, bestReview: [{ title: ‘meraviglioso mi ha cambiato la vita’ }], worstReview: [{ title: ‘a me mi pare una…’ }] }
  18. 18. @mauroservienti#webappconf17 Act
  19. 19. @mauroservienti#webappconf17 Act mutation{ post: addToCart( id: 123, quantity: 2 ){ cartId, itemTotalPrice, cartTotalPrice } }
  20. 20. @mauroservienti#webappconf17 Act mutation{ post: addToCart( id: 123, quantity: 2 ){ cartId, itemTotalPrice, cartTotalPrice } }
  21. 21. @mauroservienti#webappconf17 Act mutation{ post: addToCart( id: 123, quantity: 2 ){ cartId, itemTotalPrice, cartTotalPrice } }
  22. 22. @mauroservienti#webappconf17 Act mutation{ post: addToCart( id: 123, quantity: 2 ){ cartId, itemTotalPrice, cartTotalPrice } } response
  23. 23. @mauroservienti#webappconf17 Systems evolution
  24. 24. @mauroservienti#webappconf17 Non-breaking / additive type Product { id: string, title: string, description: string, unitPrice: price, delivery: deliveryEnum, weight: float, stars: float, reviews: [{ title: string, quality: sentimentEnum, text: string, }] }
  25. 25. @mauroservienti#webappconf17 Non-breaking / additive type Product { id: string, title: string, description: string, unitPrice: price, delivery: deliveryEnum, weight: float, stars: float, reviews: [{ title: string, quality: sentimentEnum, text: string, }] customersAlsoBuy: [Product] }
  26. 26. @mauroservienti#webappconf17 Breaking type Product { id: string, title: string, description: string, unitPrice: price, delivery: deliveryEnum, weight: float, stars: float, reviews: [{ title: string, quality: sentimentEnum, text: string, }] customersAlsoBuy: [Product] }
  27. 27. @mauroservienti#webappconf17 Breaking const resolverMap = { Product: { customersAlsoBuy( obj, args, context, info ){ //do whatever you want :) return ….; }, }, };
  28. 28. @mauroservienti#webappconf17 Recap • It’s a specification, not an implementation • Clients, within schema bounds, decide what they want • When schema evolves services can easily be backward compatible • A Node.js reference implementation is provided • @ graphql.org: • Samples • Implementations for different stacks (graphql.org/code/) • Intro tutorials and guidance
  29. 29. @mauroservienti#webappconf17 Mauro Servienti Solution Architect @ Particular Software makers of NServiceBus mauro.servienti@particular.net //blogs.ugidotnet.org/topics //milestone.topics.it
  30. 30. @mauroservienti#webappconf17 Thank you!

Editor's Notes

  • Inventato da Facebook. Hanno dichiarato di non aver introdotto una sola breaking change negli ultimi 2 anni
    Recentemente adottato da GitHub
  • Se non avete controllo sui client (fai un esempio) il vostro peggior incubo sono le breaking change, in caso contrario il problema è molto relativo.
    È molto semplice non ve le potete permettere. Fine de giochi.
    Diciamo che in sistemi enormi (Amazon, Facebook, GitHub, i Bancomat nel mondo) possiamo dire che siamo esattamente in questa situazione
    Avete quindi il problema che il business evolve, quindi i servizi evolvono e i client (o in generale chi interroga una API) non sono sotto il vostro controllo
    la conseguenza è che in un dato momento T è molto probabile che un client non sia in grado di consumare una API che è cambiata
  • Attenzione che addictive o branching evolution non sono mai un problema, la rimozione di informazioni e quindi la contrazione dello schema è una disruptive change, che implica un profondo cambiamento nel business.
  • I metadati
  • I metadati
  • I metadati
  • I metadati
    Tipi che a loro volta possono essere custom type
  • I metadati
    Altre informazioni semplici
  • I metadati
    E infine un nuovo tipo complesso, che dichiara una «releazione» 1 -> n
  • Notate il salto di qualità? La semantica anche nelle query
  • Mutations
  • Mutations
  • Che cosa voglio fare
  • Con quali informazioni
  • Che cosa voglio come risposta
  • Allo stesso modo la cooperazione avviene sulle mutation
  • Se non avete controllo sul client non potete sperare di dettare cosa il client vuole, è il client che decide
    Quello che potete fare quindi è:
    definire lo schema
    Dare ad ogni servizio la possibilità di partecipare nella costruzione della risposta o nell’esecuzione della mutazione
    A questo il client, nei limiti dello schema, può decidere cosa vuole
    Se lo schema evolve i servizi possono garantire retrocompatibilità per la loro parte
  • domande

×