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

GraphQL: The next evolution for Web APIs?

GraphQL: The next evolution for Web APIs?

REST has become the de-facto standard for web APIs. However the constraints imposed by the standard sometimes make it hard to work with. What if you want to get a list of all posts written by a user and all friends of that user that liked the post? In REST this means hitting at least 4 different API endpoints. In GraphQL, a new approach to interacting with an API, this same operation could be done with only one request! In this webinar we will go over the general structure of GraphQL, key differences to REST and then look at a client-server example implementation to see hands-on how the same use case looks like in REST and GraphQL.

Marcel Neidinger

June 16, 2020
Tweet

More Decks by Marcel Neidinger

Other Decks in Programming

Transcript

  1. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential graphql { old_times what how why examples }
  2. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential Kid, let me take you back to 2019 …
  3. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential … when we could still travel …
  4. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential … and used REST to do API interactions
  5. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential Webex API GET /api/v1/people/me HTTP/1.1 200 OK Date: Thu, 10 Oct 2019 03:59:02 GMT Content-Type: application/json { “id”: “Y2lzY29zcGFyazovL3VzLA”, ”emails”: [ “[email protected]” } } Header Body Location Method Identifier
  6. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential /api/subreddit/ /api/user/ /api/user/ /api/user/ /api/subreddit/<name>/posts /api/post/<post>/comments/ /api/post/<post>/comments/ /api/post/<post>/comments/
  7. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential We added more and more of these
  8. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential we are relationship- driven
  9. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential under-fetching The process of being unable to fetch all data required in a single request.
  10. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential over-fetching The process of getting unnecessary information when querying a API endpoint.
  11. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential SELECT (name, joke) FROM presentation WHERE level > 1 0 Rows returned
  12. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.
  13. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential 2012 Dev at fb 2015 Open Source
  14. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential 2012 Dev at fb 2015 Open Source
  15. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential 2012 Dev at fb 2015 Open Source 2018 GraphQL Foundation
  16. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential 2012 Dev at fb 2015 Open Source 2018 GraphQL Foundation
  17. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential 2012 Dev at fb 2015 Open Source 2018 GraphQL Foundation Now Significant Adoption
  18. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.
  19. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! }
  20. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! }
  21. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! }
  22. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! }
  23. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! }
  24. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! }
  25. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! hotListings(limit: Int):[RedditLink]! }
  26. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! hotListings(limit: Int):[RedditLink]! }
  27. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! hotListings(limit: Int):[RedditLink]! }
  28. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubReddit{ name: String! title: String! hotListings(limit: Int):[RedditLink]! }
  29. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubRedditQueries{ search(q: String): [SubReddit] getSubReddit(uuid: Id): SubReddit }
  30. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubRedditQueries{ search(q: String): [SubReddit] getSubReddit(uuid: Id): SubReddit }
  31. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubRedditQueries{ search(q: String): [SubReddit] getSubReddit(uuid: Id): SubReddit }
  32. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubRedditQueries{ search(q: String): [SubReddit] getSubReddit(uuid: Id): SubReddit }
  33. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubredditMutations{ addLike(num: Int): SubReddit }
  34. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubredditMutations{ addLike(num: Int): SubReddit }
  35. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential addLike(num: 1) { name title }
  36. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubredditSubscriptions { onSubscriber(name: str): Subscriber }
  37. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential { “id”: “…” “name”: “…” } { “id”: “…” “name”: “…” }
  38. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential schema { query: SubRedditQueries mutation: SubredditMutations subscription: SubredditSubscriptions }
  39. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubRedditQueries{ getSubReddit(uuid: Id): SubReddit }
  40. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubRedditQueries{ getSubReddit(uuid: Id): SubReddit }
  41. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubRedditQueries{ getSubReddit(uuid: Id): SubReddit } SubRedditResolver
  42. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubRedditQueries{ getSubReddit(uuid: Id): SubReddit } type SubReddit{ name: String! title: String! hotListings(limit: Int):[RedditLink]! } SubRedditResolver
  43. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential type SubRedditQueries{ getSubReddit(uuid: Id): SubReddit } type SubReddit{ name: String! title: String! hotListings(limit: Int):[RedditLink]! } SubRedditResolver RedditLinkResolver
  44. © 2019 Cisco and/or its affiliates. All rights reserved. Cisco

    Confidential • List of GraphQL APIs: https://github.com/APIs-guru/graphql-apis • Online Playground for GraphQL: https://www.graphqlhub.com/playground • Step-by-Step Guide on GraphQL: https://www.howtographql.com/ Useful Resources