Implementing and using GraphQL at GitHub

Dd18bb36fa5f06e45843ff8de33b793e?s=47 Kyle Daigle
September 14, 2016

Implementing and using GraphQL at GitHub

This talk was given at GitHub Universe 2016. Alongside Dan Schafer from GitHub, we discuss GraphQL, the what's and the hows, and how GitHub has launched its public GraphQL API.

Dd18bb36fa5f06e45843ff8de33b793e?s=128

Kyle Daigle

September 14, 2016
Tweet

Transcript

  1. Implementing and Using GraphQL Kyle Daigle Platform Interface Engineering Manager,

    GitHub Dan Schafer Software Engineer, Co-Creater of GraphQL, Facebook
  2. Kyle Daigle @kdaigle kdaigle@github.com

  3. Today • Over 250,000 OAuth Applications • Over 6,000,000 users

    have installed an OAuth app • REST API v3 • Webhooks
  4. But not without some pain...

  5. Pains of our API • Getting the data you want

    can be multiple REST calls away • It’s difficult for us to release comprehensive REST responses that don’t expose too much data that’s too expensive to calculate. • When we’re forced to make a change, it’s very hard to know who it will impact • GitHub uses the API for its own integrations but not for product features
  6. Announcing GitHub GraphQL API

  7. We did some investigation...

  8. Built a proof of concept...

  9. Woah.

  10. githubengineering.com

  11. We headed to the source...

  12. Introduction to GraphQL Dan Schafer Software Engineer, Facebook

  13. Why GraphQL?

  14. None
  15. Join-tables http://url.api/reso

  16. None
  17. GraphQL

  18. { me { name } }

  19. { "me": { "name": "Daniel Schafer" } } { me

    { name } }
  20. { me { name profilePic { width height url }

    } }
  21. { "me": { "name": "Daniel Schafer", "profilePic": { "width": 50,

    "height": 50, "url": "https://cdn/50.jpg" } } } { me { name profilePic { width height url } } }
  22. { me { name friends { name } } }

    { "me": { "name": "Daniel Schafer", "friends": [ { "name": "Kyle Daigle" }, { "name": "Nick Schrock" }, { "name": "Lee Byron" },
  23. { me { name friends { name events { name

    } } } } { "me": { "name": "Daniel Schafer", "friends": [ { "name": "Kyle Daigle", "events": [ { "name": "Github Universe" }, { "name": "GraphQL Meetup" }, ] }
  24. { me { name friends(first: 1) { name events(first: 1)

    { name } } } } { "me": { "name": "Daniel Schafer", "friends": [ { "name": "Kyle Daigle", "events": [ { "name": "Github Universe" } ] } ] } }
  25. Benefits of GraphQL

  26. Mental Model for
 Product Developers

  27. Type System

  28. { me { name friends(first: 1) { name events(first: 1)

    { name } } } }
  29. { me { name friends(first: 1) { name events(first: 1)

    { name } } } }
  30. { me { name friends(first: 1) { name events(first: 1)

    { name } } } } type Query { me: User user(id: Int): User }
  31. { me { name friends(first: 1) { name events(first: 1)

    { name } } } } type User { name: String profilePic(size: Int = 50): Image friends(first: Int): [User] events(first: Int): [Event] }
  32. { me { name friends(first: 1) { name events(first: 1)

    { name } } } } type User { name: String profilePic(size: Int = 50): Image friends(first: Int): [User] events(first: Int): [Event] }
  33. { me { name friends(first: 1) { name events(first: 1)

    { name } } } } type Event { name: String attendees(first: Int): [User] }
  34. { me { name attendees(first: 1) { name } }

    }
  35. { me { name attendees(first: 1) { name } }

    }
  36. { me { name attendees(first: 1) { name } }

    } type User { name: String profilePic(size: Int = 50): Image friends(first: Int): [User] events(first: Int): [Event] }
  37. Introspection

  38. { __schema { types { name fields { name type

    { name } } } } } type Query { me: User user(id: Int): User } type User { name: String profilePic(size: Int = 50): Image friends(first: Int): [User] events(first: Int): [Event] } type Event { name: String attendees(first: Int): [User] }
  39. Power to the Clients

  40. Models Views Here's your 123 model CLIENT Model: 123, plz

    APP SERVER
  41. Models Views v2 Here's your 123 model CLIENT Model: 123,

    plz APP SERVER
  42. Models Models v2 Here's your 123 v2 model CLIENT Model:

    123, v2, plz APP SERVER Views v2
  43. CLIENT APP SERVER Views v3 Models Models v2 Models v3

    Here's your 123 v3 model Model: 123, v3, plz
  44. CLIENT APP SERVER Models v2 Models v3 Models v4 Views

    v4 Here's your 123 v4 model Model: 123, v4, plz
  45. Models Views Here's your 123 model CLIENT Model: 123, plz

    APP SERVER Model: 123, plz Model: 123, plz Model: 123, plz Model: 123, plz Model: 123, plz
  46. Capabilities Requirements CLIENT APP SERVER

  47. Type System Views Models This data shape, plz Here's your

    specific data CLIENT APP SERVER
  48. Views v2 Views Models Models v2 This data shape, plz

    Here's your specific data CLIENT APP SERVER Type System
  49. Views v3 Views v2 Views Models Models v2 Models v3

    This data shape, plz Here's your specific data CLIENT APP SERVER Type System
  50. iOS Feed Android Feed Ads Manager iPad Pages iOS Messenger

    Facebook Lite
  51. GraphQL

  52. graphql.org

  53. We love collaborating on GraphQL.

  54. rmosolgo/graphql-ruby shopify/graphql-batch

  55. We are changing how we work to help improve the

    platform.
  56. We felt this building the Projects REST API.

  57. None
  58. Be transparent.

  59. Public GitHub Platform Roadmap developer.github.com

  60. Collaborate directly
 with integrators.

  61. platform.github.community

  62. None
  63. GitHub Platform Forum • Public forum to discuss early access

    and pre-release features • Staffed by GitHub Platform Engineers, Product Managers, and Support staff • Feedback can immediately be used by GitHub engineers • Integrators can work with each other to share novel uses and best practices
  64. Change how we build features at GitHub.

  65. Early Access Program

  66. Early Access Program • We will provide a communication channel

    to collaboratively impact the direction and approach of a project. • We will strive to keep documentation updated, but you can expect unannounced breaking changes as we develop quickly. • We may stop or pause access to Early Access releases at any point. • You will encounter bugs and there will be reliability and stability hiccups.
  67. Systemic support from Product Managers, Support, and Engineers makes this

    possible.
  68. GitHub Engineers building on top of the same platform.

  69. Access to more data sooner.

  70. We’re solving new problems with GraphQL in the public.

  71. Using OAuth tokens to limit field & object visibility.

  72. query { viewer } user

  73. query { viewer { repositories(first: 3) { edges { node

    { name } } } } } user repo
  74. Will change to support Integrations’ new permission system.

  75. Keeping some schema bits internal while letting the rest be

    public.
  76. User = GraphQL::Object.define do name “User” available_for_targets [:public] end

  77. User = GraphQL::Object.define do name “User” available_if_flagged [:super_secret_ship] end

  78. There are also a lot of cool parts of GraphQL

    in public.
  79. Query Introspection

  80. Let’s give it a shot.

  81. developer.github.com

  82. github/graphql-client

  83. github/github-graphql-rails-example

  84. graphql.org

  85. platform.github.community

  86. None
  87. FIN