GraphQL ou APIs RESTful - DevDay 2017

  • View
    102

  • Download
    0

Embed Size (px)

Text of GraphQL ou APIs RESTful - DevDay 2017

  1. 1. @marcosbrizeno
  2. 2. O que GraphQL
  3. 3. GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data. http://graphql.org/learn/
  4. 4. Type Query { me: User } Type User { id: ID name: String }
  5. 5. Type Query { me: User } Type User { id: ID name: String } { me { name } }
  6. 6. { "me": { "name": "Luke Skywalker" } } Type Query { me: User } Type User { id: ID name: String } { me { name } }
  7. 7. Como funciona na prtica? POST http://localhost/graphql { "query" : "query { me { name } }" }
  8. 8. Como funciona na prtica? POST http://localhost/graphql { "query" : "query { me { name } }" } Response { "data" : { "me" : { "name" : "Luke Skywalker" } } }
  9. 9. De onde veio GraphQL? Prottipo em 2012 https://youtu.be/zVNrqo9XGOs
  10. 10. De onde veio GraphQL? Prottipo em 2012 2015 Falaram sobre GraphQL https://youtu.be/zVNrqo9XGOs
  11. 11. De onde veio GraphQL? Prottipo em 2012 2015 Falaram sobre GraphQL Mais tarde (Julho) foi OSS (JavaScript) https://youtu.be/zVNrqo9XGOs
  12. 12. De onde veio GraphQL? Prottipo em 2012 2015 Falaram sobre GraphQL Mais tarde (Julho) foi OSS (JavaScript) 2016 Production Ready https://youtu.be/zVNrqo9XGOs
  13. 13. Explorando APIs GraphQL Com GraphiQL!
  14. 14. GraphiQL is a graphical interactive in-browser GraphQL IDE. https://github.com/graphql/graphiql
  15. 15. https://github.com/graphql/graphiql
  16. 16. http://graphql.org/swapi-graphql/
  17. 17. GraphiQL http://graphql.org/swapi-graphql/
  18. 18. Show me the Code! Acessando a API do Github
  19. 19. Quais linguagens tenho utilizado nos meus ltimos repositrios?
  20. 20. API Rest GET /user/repos Response
  21. 21. API Rest GET /user/repos Response
  22. 22. API Rest GET /repos/:owner/:repo/languages Response
  23. 23. API Rest 10x
  24. 24. API GraphQL do Github https://developer.github.com/v4
  25. 25. API GraphQL do Github https://developer.github.com/v4/explorer/
  26. 26. https://developer.github.com/v4/explorer/
  27. 27. https://developer.github.com/v4/explorer/
  28. 28. https://developer.github.com/v4/explorer/
  29. 29. https://developer.github.com/v4/explorer/
  30. 30. https://developer.github.com/v4/explorer/
  31. 31. https://developer.github.com/v4/explorer/
  32. 32. Show me the Code! [2] Criando uma API GraphQL
  33. 33. Gemfile
  34. 34. Gemfile $> bundle
  35. 35. Gemfile $> bundle $> rails g graphql:install
  36. 36. Gemfile $> bundle $> rails g graphql:install routes.rb
  37. 37. app/controllers/graphql_controller.rb
  38. 38. app/controllers/graphql_controller.rb
  39. 39. app/graphql/leave_management_schema.rb
  40. 40. app/graphql/leave_management_schema.rb
  41. 41. app/graphql/types/query_type.rb
  42. 42. app/graphql/types/query_type.rb
  43. 43. app/graphql/types/query_type.rb
  44. 44. app/graphql/types/query_type.rb
  45. 45. app/graphql/types/leave_query_type.rb
  46. 46. app/graphql/types/leave_query_type.rb
  47. 47. app/graphql/types/leave_query_type.rb
  48. 48. app/graphql/types/leave_query_type.rb
  49. 49. app/graphql/types/consultant_query_type.rb
  50. 50. app/graphql/types/consultant_query_type.rb
  51. 51. http://localhost:3001/graphiql
  52. 52. E a? GraphQL ou REST
  53. 53. Ningum usa GraphQL - O Github j t usando! - Retrabalho para novos consumidores
  54. 54. O Github j usa GraphQL! - A verso nova da API (v4) no REST - Github v3 o primeiro resultado no google
  55. 55. GraphQL mais fcil de evoluir - Evoluir os modelos do grafo mais fcil do que criar uma nova verso da API - Mudanas destrutivas continuam quebrando os clientes, e GraphQL no versiona
  56. 56. GraphQL mais fcil de codar - Uma vez que o grafo definido, fcil reutiliz-lo
  57. 57. GraphiQL facilita muito a Developer Experience - Consumidores podem explorar os dados e criar suas consultas (alm de ver a documentao)
  58. 58. GraphQL facilita muito a Developer Experience - APIs REST precisam que voc implemente customizaes da resposta
  59. 59. GraphQL + BFF =