Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GraphQL

 GraphQL

Does REST feel kind of old school and tedious? Do you have endpoints for everything? Fear not! GraphQL is here to save the day. Or is it?

Christian Leo-Pernold

June 25, 2020
Tweet

More Decks by Christian Leo-Pernold

Other Decks in Technology

Transcript

  1. GraphQL

  2. About me ! Christian Leo-Pernold "#$%&'(⛰*+,- . @mazedlx ⭐ github.com/mazedlx

    0 mazedlx.net 1 repod.at 1 gusch.fredl.at 2/55
  3. Let's talk about APIs 3/55

  4. REST REpresentational State Transfer 4/55

  5. 5/55

  6. 1. GET /episodes/1 6/55

  7. 1. GET /episodes/1 2. GET /actors/1 7/55

  8. 1. GET /episodes/1 2. GET /actors/1 3. GET /actors/2 8/55

  9. 1. GET /episodes/1 2. GET /actors/1 3. GET /actors/2 4.

    GET /actors/3 9/55
  10. 1. GET /episodes/1 2. GET /actors/1 3. GET /actors/2 4.

    GET /actors/3 5. GET /actors/4 10/55
  11. 1. GET /episodes/1 2. GET /actors/1 3. GET /actors/2 4.

    GET /actors/3 5. GET /actors/4 6. GET /reviews/1 11/55
  12. 6 calls to the API 12/55

  13. 13/55

  14. GET /episodes/1 14/55

  15. 15/55

  16. But then things change 16/55

  17. GET /episodes/1 GET /episodes_with_everything_i_need/1 GET /episodes_with_everything_also_highres_images/1 GET /episodes_with_everything_but_for_mobile/1 GET /episodes_with_everything_for_iphone_only_v2/1

    GET /episodes_with_everything_but_without_images/1 ... GET /episodes_with_everything_but_without_reviews/1 17/55
  18. 18/55

  19. What if we could just tell the API what we

    want? 19/55
  20. GraphQL 20/55

  21. A query language for your API 21/55

  22. Created by Facebook 22/55

  23. 23/55

  24. Open Source 24/55

  25. PHP, Python, Ruby, Java, Go, JavaScript, Node, Angular, React, Vue,

    Ember and more 25/55
  26. Facebook GitHub Shopify Yelp Pinterest 26/55

  27. GraphQL isn't: 27/55

  28. a silver bullet 28/55

  29. a REST replacement 29/55

  30. 30/55

  31. 31/55

  32. 32/55

  33. 33/55

  34. 34/55

  35. Problem ❌ N+1 35/55

  36. REST 36/55

  37. GraphQL 37/55

  38. Solution ✅ Batching with Dataloaders 38/55

  39. Problem ❌ Caching 39/55

  40. GET /episodes/1 40/55

  41. POST /graphql 41/55

  42. How does one cache a POST request? 42/55

  43. Solution ✅ Caching with Dataloaders 43/55

  44. Problem ❌ Schema Duplication 44/55

  45. 45/55

  46. 46/55

  47. Solution ✅ Schema Generators 47/55

  48. Problem ❌ Poor Performance 48/55

  49. Solution ✅ Query Caching 49/55

  50. It's Demo Time! Laravel app (^7.0) Users, articles and comments

    1.000 articles, 3.000 comments, 4.000 users seeded Eloquent relations are set 50/55
  51. GraphQL is (kind of) self-documenting 51/55

  52. & PHP 52/55

  53. Laravel https://github.com/nuwave/lighthouse Symfony https://github.com/overblog/GraphQLBundle 53/55

  54. Plain PHP https://github.com/webonyx/graphql-php GraphQL Framework in PHP https://github.com/railt/railt 54/55

  55. !" Slides can be found at speakerdeck.com/mazedlx 55/55