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

Introduction to GraphQL for Android dev

Introduction to GraphQL for Android dev

Avatar for Ivan Savytskyi

Ivan Savytskyi

March 24, 2017
Tweet

Other Decks in Programming

Transcript

  1. What is GraphQL GRAPHQL IS A QUERY LANGUAGE FOR YOUR

    API, A N D A S E RV E R - S I D E R U N T I M E F O R E X E C U T I N G QUERIES BY USING A TYPE SYSTEM YOU DEFINE FOR YOUR DATA.
  2. Client RestAPI /users getUserList user list (length: n) RestAPI /user/repo/{:id}

    getUserRepo(id:1) getUserRepo(id:2) getUserRepo(id:n) R : 1 R : 2 R : 3 R : n+1 N + 1 query problem Client GraphQL Server getUserWithRepos user with repo list REST GraphQL R : 1
  3. GraphQL Schema "kind": "OBJECT", "name": "User", "description": "A user is

    an individual's account on GitHub that owns repositories and … "fields": [{ "name": "avatarURL", "description": "A URL pointing to the user's public avatar.", "args": [{ "name": "size", "description": "The size of the resulting square image.", "type": { "kind": "SCALAR", "name": “Int" }, "defaultValue": null }], "type": { "kind": "NON_NULL", "ofType": { "kind": "SCALAR", "name": "String" } }, "isDeprecated": false, "deprecationReason": null
  4. … "name": "gist", "description": "Find gist by repo name.", "args":

    [{ "name": "name", "description": "The gist name to find.", "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "SCALAR", "name": "String", } }], "type": { "kind": "OBJECT", "name": "Gist" }, "isDeprecated": false, "deprecationReason": null GraphQL Schema
  5. Graph Root User Repo Search Gist Connection Gist Repo Connection

    PullRequest Connection PullRequest description, isDeprecated fields: [ avatarUrl:String, bio:String, …
  6. Schema only generation ApiSchema.query( root -> root.user( args -> args.login(“efung”),

    user -> user .name() .bio() .avatarURL(args -> args.size(48)) .company() .repositories( args -> args.first(100), repo -> repo .id() .name() ) ).build() query{ user(login:”efung”){ name bio avatarURL(size:48) company repositories(first:100){ node { id name } } } }
  7. Schema + query generation /src/graphql/com/example/schema.json /src/graphql/com/example/query.graphql query UserWithRepos($login:String!){ user(login:$login){ name

    bio avatarURL(size:48) company repositories(first:100){ node { id name } } } } class UserWithRepos{ final String OPERATION_DEFINITION = “” class Variables{ String login; } class User{ String name; String bio; String avatarURL; String company; RepositoryConnection repositories; class RepositoryConnection{ List<Node> nodes; class Node{ String id; String name; } } } } http://dev.apollodata.com/