Introduction to GraphQL

Introduction to GraphQL

GraphQL is a new API standard that provides a more efficient, powerful and flexible alternative to REST. At its core, GraphQL enables declarative data fetching where a client can specify exactly what data it needs from an API. Instead of multiple endpoints that return fixed data structures, a GraphQL server only exposes a single endpoint and responds with precisely the data a client asked for. In this talk, I will give you an introduction to GraphQL and then show you how to use it to access Github’s GraphQL API.

Da526e4b5901b3a2759cf234285c6488?s=128

Jennifer Bland

September 22, 2018
Tweet

Transcript

  1. Introduction to GraphQL Jennifer Bland

  2. Three Truths and One Lie •I have visited 82 countries

    •I graduated from college before IBM introduced the IBM PC •My home is 400 sq ft •I have never been west of the Mississippi River
  3. www.jenniferbland.com @ratracegrad ratracegrad@gmail.com youtube.com/c/jenniferbland !3

  4. What Is GraphQL?

  5. A programming language !5

  6. A special type of database !6

  7. A library !7

  8. What Is GraphQL?

  9. Graph QUERY LANGUAGE

  10. Why GraphQL?

  11. !1 1

  12. !1 2

  13. Get the Data 13 /dynamic-content/projects/v1/1 /dynamic-content/homepage/v2/1

  14. !1 4

  15. Why GraphQL?

  16. None
  17. !1 7

  18. !1 8

  19. Components

  20. Schema

  21. None
  22. 22 // GET ‘/graphql { projects {
 title image }

    } // result { projects {
 title: “Build a Fire Pit image: “firepit.png” } }
  23. 23

  24. 24

  25. 25

  26. • Schema is strongly-typed • Client picks what they need

    • It’s fast • It’s flexible
  27. Queries

  28. Queries 28 query { projects } query { projects {

    title image }
  29. Queries 29 query { relatedProjects { # this is an

    array title image details { description tools category }
  30. Queries 30 query { relatedProjects(id: 72113) { title image details

    { description tools category }
  31. Queries 31 query getRelatedProject($id: String) { relatedProjects(id: $id) { title

    image details { description tools category }
  32. Resolvers

  33. Resolvers 33 Query: { relatedProjects (root, args) { return Projects.find({

    id: args.id }); } }
  34. Resolvers 34 Post: { author(post) { return Users.find({ id: post.authorId})

    }, commentsCount(post) { return Comments.find({ postId: post.id}).count() } }
  35. Demo

  36. Resources graphqlweekly.com howtographql.com graphqlhub.com developer.github.com/v4/explorer/

  37. Three Truths and One Lie •I have visited 82 countries

    •I graduated from college before IBM introduced the IBM PC •My home is 400 sq ft •I have never been west of the Mississippi River
  38. Jennifer Bland www.jenniferbland.com ratracegrad@gmail.com