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

Bringing GraphQL to iOS – Berlin GraphQL meetup Nov 2016

Bringing GraphQL to iOS – Berlin GraphQL meetup Nov 2016

Martijn Walraven

November 09, 2016
Tweet

More Decks by Martijn Walraven

Other Decks in Programming

Transcript

  1. C L I E N T S E R V

    E R GET users/apollostack/repos [ { "id": 67563416, "name": "android-docs", "full_name": "apollostack/android-docs", "owner": { "login": "apollostack", "id": 17189275, "avatar_url": "https://avatars.githubusercontent.com/u/17189275?v=3", "gravatar_id": "", "url": "https://api.github.com/users/apollostack", "html_url": "https://github.com/apollostack", "followers_url": "https://api.github.com/users/apollostack/followers", "following_url": "https://api.github.com/users/apollostack/following{/other_user}", "gists_url": "https://api.github.com/users/apollostack/gists{/gist_id}", "starred_url": "https://api.github.com/users/apollostack/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/apollostack/subscriptions", "organizations_url": "https://api.github.com/users/apollostack/orgs", "repos_url": "https://api.github.com/users/apollostack/repos", "events_url": "https://api.github.com/users/apollostack/events{/privacy}", "received_events_url": "https://api.github.com/users/apollostack/received_events", "type": "Organization", "site_admin": false }, "private": false, Overfetching
  2. C L I E N T S E R V

    E R GET repos/apollostack/apollo-client/contributors GET users/apollostack/repos GET repos/apollostack/react-apollo/contributors GET repos/apollostack/apollo-ios/contributors [{"login":"stubailo","id":448783,"avatar_url":"https:// avatars.githubusercontent.com/u/448783? v=3","gravatar_id":"","url":"https://api.github.com/users/ stubailo","html_url":"https://github.com/ stubailo","followers_url":"https://api.github.com/users/ stubailo/followers","following_url":"https://api.github.com/ [{"login":"stubailo","id":448783,"avatar_url":"https:// avatars.githubusercontent.com/u/448783? v=3","gravatar_id":"","url":"https://api.github.com/users/ stubailo","html_url":"https://github.com/ stubailo","followers_url":"https://api.github.com/users/ stubailo/followers","following_url":"https://api.github.com/ [{"login":"stubailo","id":448783,"avatar_url":"https:// avatars.githubusercontent.com/u/448783? v=3","gravatar_id":"","url":"https://api.github.com/users/ stubailo","html_url":"https://github.com/ stubailo","followers_url":"https://api.github.com/users/ stubailo/followers","following_url":"https://api.github.com/ [ { "id": 67563416, "name": "android-docs", "full_name": "apollostack/android-docs", "owner": { "login": "apollostack", "id": 17189275, "avatar_url": "https://avatars.githubusercontent.com/u/17189275?v=3", "gravatar_id": "", "url": "https://api.github.com/users/apollostack", "html_url": "https://github.com/apollostack", "followers_url": "https://api.github.com/users/apollostack/followers", "following_url": "https://api.github.com/users/apollostack/following{/other_user}", "gists_url": "https://api.github.com/users/apollostack/gists{/gist_id}", "starred_url": "https://api.github.com/users/apollostack/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/apollostack/subscriptions", "organizations_url": "https://api.github.com/users/apollostack/orgs", "repos_url": "https://api.github.com/users/apollostack/repos", "events_url": "https://api.github.com/users/apollostack/events{/privacy}", "received_events_url": "https://api.github.com/users/apollostack/received_events", "type": "Organization", "site_admin": false }, "private": false, "html_url": "https://github.com/apollostack/android-docs", "description": "[WIP] :book: Docs for using Apollo with Android", "fork": false, "url": "https://api.github.com/repos/apollostack/android-docs", "forks_url": "https://api.github.com/repos/apollostack/android-docs/forks", "keys_url": "https://api.github.com/repos/apollostack/android-docs/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/apollostack/android-docs/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/apollostack/android-docs/teams", "hooks_url": "https://api.github.com/repos/apollostack/android-docs/hooks", Extra roundtrips
  3. Fundamental tension between efficiently satisfying the data needs of specific

    clients, and keeping the number of endpoints manageable on the server
  4. Capabilities Data needs type Post { id: Int! title: String

    author: Author votes: Int } Q U E R Y S C H E M A query { posts { title } } { "data": { "posts": [ { "title": "Introduction to GraphQL" }, { "title": "GraphQL Rocks" }, { "title": "Advanced GraphQL" } ] } }
  5. “GraphQL starts with their way of thinking and requirements and

    builds the language and runtime necessary to enable that.”
  6. Schema acts as a strongly typed 
 and self-documenting contract

    
 between frontend and backend type Post { id: Int! title: String author: Author votes: Int } type Author { id: Int! firstName: String lastName: String posts: [Post] }
  7. const authors = [ { id: 1, firstName: 'Tom', lastName:

    'Coleman' }, { id: 2, firstName: 'Sashko', lastName: 'Stubailo' }, ]; const posts = [ { id: 1, authorId: 1, title: 'Introduction to GraphQL', votes: 2 }, { id: 2, authorId: 2, title: 'GraphQL Rocks', votes: 3 }, { id: 3, authorId: 2, title: 'Advanced GraphQL', votes: 1 }, ]; const resolveFunctions = { Query: { posts() { return posts; }, }, Author: { posts(author) { return filter(posts, { authorId: author.id }); }, }, Post: { author(post) { return find(authors, { id: post.authorId }); }, } };
  8. curl -X POST -H 'Content-Type:application/json' -d '{ "query": "{ posts

    { title } }"}' http://localhost:8080/graphql { "data": { "posts": [ { "title": "Introduction to GraphQL" }, { "title": "GraphQL Rocks" }, { "title": "Advanced GraphQL" } ] } }
  9. type Post { id: Int! title: String author: Author votes:

    Int } type Author { id: Int! firstName: String lastName: String posts: [Post] }
  10. type Post { id: Int! title: String author: Author votes:

    Int } type Author { id: Int! firstName: String lastName: String posts: [Post] } Type models struct Post { let id: Int? let title: String? let author: Author? let votes: Int? } struct Author { let id: Int? let firstName: String? let lastName: String? let posts: [Post]? }
  11. query { posts { title author { firstName } }

    } Query models struct Post { let title: String? let author: Author? struct Author { let firstName: String? } }
  12. GraphQL is a great fit for 
 component-based UI development

    fragment PostDetails on Post { title author { firstName } }
  13. query { posts { ...PostDetails } } fragment PostDetails on

    Post { title author { firstName } } Fragment models struct PostDetails { let title: String? let author: Author? struct Author { let firstName: String? } }
  14. Know anyone who wants to work on GraphQL technology full

    time? We’re hiring! @martijnwalraven @apollographql http://www.apollodata.com github.com/apollostack