— Query Language for your API developed at Facebook.
— Polyglot implementation for client and server - Java, Javascript,
Python, etc…
— Reduces API requests needed and only gives you that data you
asked for.
What is GraphQL?
Slide 3
Slide 3 text
Problem
— Too many API requests per month.
— Would be good to get data for a
month in request.
Slide 4
Slide 4 text
GraphQL Overview
query GetMonthData {
campaign {
date range
posts {
title
created date
}
…
}
}
Return Result
Fetches Data
Validates
Client Server
Slide 5
Slide 5 text
GraphQL Overview
query GetMonthData {
campaigns {
title
posts {
title
}
…
}
}
Return Result
Fetches Data
Validates
Query Result
{
campaigns {
[ {
title: “Campaign 1”
posts: [
title: “Post 1”
]
} …
]
}
}
Slide 6
Slide 6 text
DATABASE
REST API
CLIENTS
GraphQL Server
Slide 7
Slide 7 text
DATABASE
REST API
GRAPHQL SERVER
CLIENTS
GraphQL Server
Slide 8
Slide 8 text
1. How to query the sever
2. Build a GraphQL server
in Kotlin
1. Add Gradle Plugin.
2. Add schema definition to app in a JSON file.
3. Add queries to files with a “.graphql” file extension.
4. Use autogenerate classes from the “.graphql” files to make calls.
Integrating Apollo Android Client
Slide 16
Slide 16 text
1. Add Apollo Gradle Plugin
Slide 17
Slide 17 text
2. Add Introspection of Schema (schema.json)
Slide 18
Slide 18 text
3. Add Queries to file with “.graphql” ext
File: queries.graphql
Slide 19
Slide 19 text
4. Use ApolloClient object to make request
Slide 20
Slide 20 text
Arguments & Variables
Slide 21
Slide 21 text
Get Details for Droid with id - 2000.
Slide 22
Slide 22 text
Get Details for Droid for any id
Slide 23
Slide 23 text
Handling arguments on Android
Slide 24
Slide 24 text
Result
Query
Slide 25
Slide 25 text
Enum Arguments
Slide 26
Slide 26 text
Supplying Enum Arguments on Android
Slide 27
Slide 27 text
Aliases & Fragments
Slide 28
Slide 28 text
Aliases
Slide 29
Slide 29 text
Aliases
Slide 30
Slide 30 text
Aliases
Slide 31
Slide 31 text
Aliases
Slide 32
Slide 32 text
Fragments
Slide 33
Slide 33 text
Fragments
Slide 34
Slide 34 text
Fragments
Slide 35
Slide 35 text
Mutations
Slide 36
Slide 36 text
Create a Review for an Episode
Slide 37
Slide 37 text
Mutating on Android
Slide 38
Slide 38 text
Mutation Result
Slide 39
Slide 39 text
2. Building a GraphQL server
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
No content
Slide 42
Slide 42 text
— GraphQL Object type
— Scalar types (String, Int, Float, Boolean)
— List type
— Interface type
— Enum type
— Union type
— Input Object type
GraphQL Type System
— Common fields between Human and Droid
— name
— height
— friends
— appearsIn
Create an interface
Slide 45
Slide 45 text
Character Interface
Slide 46
Slide 46 text
Droid GraphQL Object
Slide 47
Slide 47 text
Human GraphQL Object
Slide 48
Slide 48 text
Enum Types
Slide 49
Slide 49 text
Schema Structure
Slide 50
Slide 50 text
Query Type
Slide 51
Slide 51 text
Parsing Queries and Returning Results
Slide 52
Slide 52 text
No content
Slide 53
Slide 53 text
— Client and server Java GraphQL implementations are not stable.
— No Kotlin only GraphQL implementation.
— Learning curve.
— Need to setup GraphQL server on top of your infrastructure. This
requires more work.
Disadvantages
Slide 54
Slide 54 text
Thanks! May the force be with
you!
Twitter: @heyitsmohit
Github: http://github.com/mysa