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

GraphQL on Rails

GraphQL on Rails

How GitHub uses GraphQL internally.

Jakob

May 04, 2017
Tweet

More Decks by Jakob

Other Decks in Programming

Transcript

  1. How people build software " " What is GraphQL? 3

    A language to specify and query APIs.
  2. How people build software " " What is GraphQL? 4

    Describe your data
 
 type User {
 login: String
 name: String
 repositories: [Repository] }
 Ask for what you want
 
 {
 user(login: "mikrobi") {
 name
 }
 }
 Get predicable results
 
 { "user": { "name": "Jakob Class" } }

  3. How people build software " " What’s the problem with

    REST APIs? 5 GET /users/mikrobi/repos?per_page=5 Task 1: Get the name of mikrobi’s top 5 repositories
  4. [ { "id": 17900437, "name": "appirater", "full_name": "mikrobi/appirater", "owner": {

    "login": "mikrobi", "id": 423347, "avatar_url": "https://avatars0.githubusercontent.com/u/423347?v=3", "gravatar_id": "", "url": "https://api.github.com/users/mikrobi", "html_url": "https://github.com/mikrobi", "followers_url": "https://api.github.com/users/mikrobi/followers", "following_url": "https://api.github.com/users/mikrobi/following{/other_user}", "gists_url": "https://api.github.com/users/mikrobi/gists{/gist_id}", "starred_url": "https://api.github.com/users/mikrobi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mikrobi/subscriptions", "organizations_url": "https://api.github.com/users/mikrobi/orgs", "repos_url": "https://api.github.com/users/mikrobi/repos", "events_url": "https://api.github.com/users/mikrobi/events{/privacy}", "received_events_url": "https://api.github.com/users/mikrobi/received_events", "type": "User", "site_admin": true }, "private": false, "html_url": "https://github.com/mikrobi/appirater",
  5. "description": "A utility that reminds your iPhone app's users to

    review the app.", "fork": true, "url": "https://api.github.com/repos/mikrobi/appirater", "forks_url": "https://api.github.com/repos/mikrobi/appirater/forks", "keys_url": "https://api.github.com/repos/mikrobi/appirater/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/mikrobi/appirater/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/mikrobi/appirater/teams", "hooks_url": "https://api.github.com/repos/mikrobi/appirater/hooks", "issue_events_url": "https://api.github.com/repos/mikrobi/appirater/issues/events{/number}", "events_url": "https://api.github.com/repos/mikrobi/appirater/events", "assignees_url": "https://api.github.com/repos/mikrobi/appirater/assignees{/user}", "branches_url": "https://api.github.com/repos/mikrobi/appirater/branches{/branch}", "tags_url": "https://api.github.com/repos/mikrobi/appirater/tags", "blobs_url": "https://api.github.com/repos/mikrobi/appirater/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/mikrobi/appirater/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/mikrobi/appirater/git/refs{/sha}", "trees_url": "https://api.github.com/repos/mikrobi/appirater/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/mikrobi/appirater/statuses/{sha}", "languages_url": "https://api.github.com/repos/mikrobi/appirater/languages", "stargazers_url": "https://api.github.com/repos/mikrobi/appirater/stargazers", "contributors_url": "https://api.github.com/repos/mikrobi/appirater/contributors", "subscribers_url": "https://api.github.com/repos/mikrobi/appirater/subscribers", "subscription_url": "https://api.github.com/repos/mikrobi/appirater/subscription", "commits_url": "https://api.github.com/repos/mikrobi/appirater/commits{/sha}", "git_commits_url": "https://api.github.com/repos/mikrobi/appirater/git/commits{/sha}", "comments_url": "https://api.github.com/repos/mikrobi/appirater/comments{/number}",
  6. "issue_comment_url": "https://api.github.com/repos/mikrobi/appirater/issues/comments{/number}", "contents_url": "https://api.github.com/repos/mikrobi/appirater/contents/{+path}", "compare_url": "https://api.github.com/repos/mikrobi/appirater/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/mikrobi/appirater/merges", "archive_url": "https://api.github.com/repos/mikrobi/appirater/{archive_format}{/ref}",

    "downloads_url": "https://api.github.com/repos/mikrobi/appirater/downloads", "issues_url": "https://api.github.com/repos/mikrobi/appirater/issues{/number}", "pulls_url": "https://api.github.com/repos/mikrobi/appirater/pulls{/number}", "milestones_url": "https://api.github.com/repos/mikrobi/appirater/milestones{/number}", "notifications_url": "https://api.github.com/repos/mikrobi/appirater/notifications{?since,all,participating}" "labels_url": "https://api.github.com/repos/mikrobi/appirater/labels{/name}", "releases_url": "https://api.github.com/repos/mikrobi/appirater/releases{/id}", "deployments_url": "https://api.github.com/repos/mikrobi/appirater/deployments", "created_at": "2014-03-19T10:37:41Z", "updated_at": "2014-03-19T10:37:41Z", "pushed_at": "2014-03-14T23:53:01Z", "git_url": "git://github.com/mikrobi/appirater.git", "ssh_url": "[email protected]:mikrobi/appirater.git", "clone_url": "https://github.com/mikrobi/appirater.git", "svn_url": "https://github.com/mikrobi/appirater", "homepage": "http://arashpayan.com/blog/index.php/2009/09/07/presenting-appirater/", "size": 224, "stargazers_count": 0, "watchers_count": 0, "language": "Objective-C", "has_issues": false,
  7. "has_projects": true, "has_downloads": true, "has_wiki": true, "has_pages": false, "forks_count": 0,

    "mirror_url": null, "open_issues_count": 0, "forks": 0, "open_issues": 0, "watchers": 0, "default_branch": "master" }, { "id": 1146825, "name": "Archivist", "full_name": "mikrobi/Archivist", "owner": { "login": "mikrobi", "id": 423347, "avatar_url": "https://avatars0.githubusercontent.com/u/423347?v=3", "gravatar_id": "", "url": "https://api.github.com/users/mikrobi", "html_url": "https://github.com/mikrobi", "followers_url": "https://api.github.com/users/mikrobi/followers", "following_url": "https://api.github.com/users/mikrobi/following{/other_user}", "gists_url": "https://api.github.com/users/mikrobi/gists{/gist_id}",
  8. How people build software " " After parsing 27 kilobytes…

    10 [ "name": "appirater", "name": "Archivist", "name": "babel", "name": "CCHMapCluster", "name": "cordova-docs" ]
  9. How people build software " " How does GraphQL solve

    this problem? 11 user(login: "mikrobi") { repositories(first: 5) { nodes { name } } } "user": { "repositories": { "nodes": [ { "name": "appirater" }, { "name": "Archivist" }, { "name": "babel" }, { "name": "CCHMapClusterController" }, { "name": “cordova-docs" } ] } }
  10. How people build software " " What’s the problem with

    REST APIs? 12 GET /orgs/:owner/repos?per_page=5 Task 2: Get the title of the first issue of the top 5 repositories # 1 request
 
 # 5 requests for :repo in [repos] GET /repos/:owner/:repo/issues/1
  11. How people build software " " How does GraphQL solve

    this problem? 13 organization(login: "rails") { repositories(first: 5) { nodes { issue(number: 1) { title } } } } "organization": { "repositories": { "nodes": [ { "issue": { "title": "Rails is not Django" } }, { "issue": null }, { "issue": { "title": "before_validation_on_create" } }, { "issue": { "title": "add_child on new records" } }, { "issue": { "title": "Does not work with Rails 2.3.8" } } ] } }
  12. How people build software " " Live demo and real

    code… 14 https://github.com/github/github-graphql-rails-example
  13. How people build software " " Thank you! 15 attendees(first:

    5) { nodes {
 name questions(first: 1) { nodes { summary
 }
 }
 } }