● What is GraphQL?
● GraphQL Features
a. Fields & Variables
b. Aliases & Directives
c. Fragments
● Demo of GraphQL querying using GraphiQL
Slide 5
Slide 5 text
What is GraphQL?
Slide 6
Slide 6 text
A query language for your API
● Developed internally by Facebook in 2012
● Publicly released in 2015
● Provides alternative for REST and ad-hoc web service
architectures
Slide 7
Slide 7 text
GraphQL is a data agent
Slide 8
Slide 8 text
GraphQL Features
Slide 9
Slide 9 text
Ask for what you need, get exactly that
Request for a github user (Live Demo)
● REST example - api.github.com/users/kingisaac95
● GraphQL example - graphqlhub.com/playground
GraphQL queries return predictable results
Slide 10
Slide 10 text
One request : Many resources
With GraphQL you can access many API resources with
just a single request.
Example (Live Demo)
Consuming Github and Twitter APIs with one request
Slide 11
Slide 11 text
Strong type system
GraphQL APIs are organized in terms of types and fields,
not endpoints.
Unlike RESTful APIs where an endpoint is defined for
each resource, you can access the capabilities of your
data from a single endpoint with GraphQL.
Slide 12
Slide 12 text
GraphQL fields
Scalar fields: Basic types that represent primitive values
like string, integer, float, boolean.
Slide 13
Slide 13 text
Complex fields: Fields that contain other data in them.
They usually have a custom type defined in the service’s
schema.
GraphQL fields
Slide 14
Slide 14 text
GraphQL Variables
Variables are ehhhhmm, Variables
They are identifiers for values used in our program, and in
GraphQL, they let us avoid string interpolation and build
dynamic queries.
$
Slide 15
Slide 15 text
Aliases
You cannot directly query the same field with different
arguments in a single request.
Aliases let you do that - rename the result of a field to anything
you want.
Example (Live Demo)
Requesting for more than one user with a single request
Slide 16
Slide 16 text
Directives
What if you want to request for a particular field in a resource
if a condition is met?
@include @skip
...these are not Twitter handles
Slide 17
Slide 17 text
Fragments
GraphQL’s reusable units for constructing sets of fields and
including them in queries.
Is it raining? Oh dear, please stay DRY!!!
Slide 18
Slide 18 text
Who is using GraphQL?
Slide 19
Slide 19 text
Why should you learn GraphQL?
Recap
● Predictable results
● Access many resources with one request
● Conditional requests
● Query single field with multiple arguments
● Scaling your application
Learn more graphql.org/learn/