Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building Modern APIs with GraphQL

113 views

Published on

With the rise of Microservice Architectures and rich mobile and web applications, APIs are more important than ever. Come learn how to tackle modern API design challenges with GraphQL, an open-source API query language used by Facebook, Amazon, Microsoft, Twitter, Virgin Trains, and more.

  • Be the first to comment

  • Be the first to like this

Building Modern APIs with GraphQL

  1. 1. S U M M I T LONDON
  2. 2. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Building Modern APIs with GraphQL Robert Zhu Principal Technical Evangelist Amazon Web Services @rbzhu S e s s i o n I D
  3. 3. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Robert Zhu Principal Technical Evangelist Amazon Web Services @rbzhu
  4. 4. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  5. 5. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T What is GraphQL? • Request (GraphQL doc) -> Response (JSON) • Language Specification • Schema (domain-specific) • Server Implementation
  6. 6. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T GraphQL is not • A Graph database query language (*) • A client-side state management solution • A solution for binary streams • Facebook Graph API • Limited to specific database(s) • Limited to JavaScript/NodeJS on the backend • Limited to use with React/Relay/Web • Limited to HTTP
  7. 7. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T GraphQL operations Query  Read Mutation  Write Subscription  Observe Event
  8. 8. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Query Structure query GetBooksForAuthor($id: ID!) { author(id: $id) { givenName, nationality, books { title isbn } } }
  9. 9. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Query Structure query GetBooksForAuthor($id: ID!) { author(id: $id) { givenName, nationality, books { title isbn } } }
  10. 10. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Query Structure query GetBooksForAuthor($id: ID!) { author(id: $id) { givenName, nationality, books { title isbn } } }
  11. 11. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Query Structure query GetBooksForAuthor($id: ID!) { author(id: $id) { givenName, nationality, books { title isbn } } }
  12. 12. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Query Structure query GetBooksForAuthor($id: ID!) { author(id: $id) { givenName, nationality, books { title isbn } } }
  13. 13. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Query Structure query GetBooksForAuthor($id: ID!) { author(id: $id) { givenName, nationality, books { title isbn } } }
  14. 14. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Query Structure query GetBooksForAuthor($id: ID!) { author(id: $id) { givenName, nationality, books { title isbn } } }
  15. 15. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  16. 16. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T History of GraphQL • 2012- Built to support Facebook mobile apps • 2015- GraphQL open sourced • 2018- GraphQL Foundation
  17. 17. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T API Technologies • REST • SOAP • gRPC • Apache Thrift • OpenAPI/Swagger • JSON-LD • HAL • OData • … and more
  18. 18. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T REST GraphQL
  19. 19. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T REST GraphQL Shared Definition No Yes
  20. 20. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T REST GraphQL Shared Definition No Yes Conceptual Model Resources Graphs
  21. 21. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T REST GraphQL Shared Definition No Yes Conceptual Model Resources Graphs Organization Federated Centralized
  22. 22. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T REST GraphQL Shared Definition No Yes Conceptual Model Resources Graphs Organization Federated Centralized Related Ops Yes No
  23. 23. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T REST GraphQL Shared Definition No Yes Conceptual Model Resources Graphs Organization Federated Centralized Related Ops Yes No Introspection No Yes
  24. 24. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T REST GraphQL Shared Definition No Yes Conceptual Model Resources Graphs Organization Federated Centralized Related Ops Yes No Introspection No Yes Data Typing Weak Strong
  25. 25. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T REST GraphQL Shared Definition No Yes Conceptual Model Resources Graphs Organization Federated Centralized Related Ops Yes No Introspection No Yes Data Typing Weak Strong Real-time No Yes
  26. 26. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Challenges for Modern APIs • Efficiency • Predictability • Versioning • Security • Documentation • Tooling • Caching • Database Integration • Real-time • … and many more
  27. 27. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Efficiency • Overfetching: response contained too much data. • Underfetching: response did not contain enough data. Make another network request. • Networks suck • Read 1 MB from SSD: 400 μs • Packet US <-> EU: 150 ms
  28. 28. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Efficiency • Avoid Overfetching and Underfetching. • Clients to declare all the data they need in a single network request. • Reduces the need for client-side joins, error handling, and retry logic.
  29. 29. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Type Safety • Predictability • Native clients • Code gen
  30. 30. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Domain Modeling • Domain Driven Design • Eric Evans, 2004 • Shared Language
  31. 31. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Versioning • Don’t
  32. 32. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Tooling & Documentation • GraphiQL provides documentation via introspection query • Docs are never out-of-date • IDE integrations via graphql-language-service • GraphQL for VSCode
  33. 33. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T
  34. 34. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Authentication and Authorization • Authentication • Who are you? • Authorization • Do you have permission?
  35. 35. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T HTTP Custom Protocol over TCP Authentication REST GraphQL RPC Business Logic Authentication Persistence Authorization
  36. 36. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T HTTP Custom Protocol over TCP Authentication REST GraphQL RPC Business Logic Authentication Persistence Authorization
  37. 37. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T When to use GraphQL Cumulative functionality time no design good design Design payoff line
  38. 38. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Getting GraphQL into Production DO NOT • Build a complete schema upfront • Try to replace your REST API in one push • Place business logic in the GraphQL layer DO • Educate your team • Choose a solution that fits with your stack • Build a simple query first (read-only) • Gradually layer in features like auth/mutations • Gradually expand schema
  39. 39. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Advanced use cases • API Gateway • 1st party vs 3rd party • Service-to-service • Domain Modeling: schema-first • Persisted Queries • Subscriptions • Live Queries
  40. 40. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Ecosystem • AWS AppSync • https://aws.amazon.com/appsync • Apollo • https://www.apollographql.com/ • Prisma • https://www.prisma.io/ • Hasura • https://hasura.io/
  41. 41. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Resources • Start here: http://graphql.org • Community: http://graphql.org/community/ • Demo: https://github.com/robzhu/tsgraphql-starwars • AppSync: https://aws.amazon.com/appsync/
  42. 42. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Thank you! S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Robert Zhu Principal Technical Evangelist Amazon Web Services @rbzhu
  43. 43. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I TS U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

×