GraphQL
- Developed by Facebook
- Used internally since 2012
- Open source version is published in July 2015
- Specification: https://facebook.github.io/graphql
- 15+ programming languages
- Sangria - the Scala GraphQL Implementation
Typical Rest API
Common Issues
-
Over-fetching
-
/products?field=name&
/products?field=description&
/products?field=variants[*].price
-
Under-fetching
-
/products?expand=productType&
/products?expand=variants[*].price.taxRate
-
API changes and evolution
- Versioning
- Deprecation
- Maintenance
GraphQL Approach
GraphQL Query
{
"data": {
"product": {
"name": "Delicious Cake",
"description": "Just taste it!"
"picture": {
"width": 150,
"height": 150,
"url": "http://..."
}
}
}
}
GraphQL Query
{
product {
name
description
picture {
width
height
url
}
}
}
We will learn...
- How to define GraphQL schema & execute queries
- Expose GraphQL API via HTTP
- Use database behind GraphQL API
- How to paginate, filter & sort results
- Model relationships & optimize queries
- Secure GraphQL API
We have learned...
- How to define GraphQL schema & execute queries
- Expose GraphQL API via HTTP
- Use database behind GraphQL API
- How to paginate, filter & sort results
- Model relationships & optimize queries
- Secure GraphQL API