Now THIS is the industry standard. REST API is so last season.
Overview
“GraphQL is the new standard for data API from Facebook, superseding REST. It allows a single data graph with strongly typed schema to serve just as much data as needed from a client. GitHub is switching to GraphQL already.”
http://graphql.org/blog says:
GraphQL has been delivering data to Facebook mobile News Feed since 2012.
Facebook released it publicly in 2015 at:
http://facebook.github.io/graphql
Community stats
The status of community as of November 5, 2015:
- 4,376 followers of Twitter account @GraphQL
- 2,328 registered on Facebook’s GraphQL Slack channel managed by Bruno Lemos.
- 540 answers tagged on StackOverflow
- 519 members who joined Facbook’s GraphQL group
- 350 attended the first #graphqlsummit (hosted by Apollo) October 26, 2016 in San Francisco
- 4,500 videos with the name on YouTube
- 45 presentations on SlideShare
- 149 members in the “GraphQL User Group” on LinkedIn which succinctly describes GraphQL thus:
There are Google Groups for specific implementations:
Why?
It was a necessity for the world’s busiest mobile app for these advantages over REST API:
-
Perform an introspection query. As the GraphQL schema matures, new data types appear.
-
Make a single call to retrieve (rather than many REST API calls).
-
Response is structured using the same JSON hierarchy as the call. A shared schema language between front-end and back-end. This is hugh.
-
Changes can occur with less fuss (pain) than REST API. No large version migrations.
-
Static queries make loading predictable, and cleaner server metric insights.
-
Schema says which fields are being used, so caching (persisted queries) is possible.
“With GraphQL, we could simply stop writing API documentation or reading it. I think that’s the dream of every developer.” - by @arunoda
Facebook Relay vs. Apollo
Facebook also released its Relay server that responds to GraphQL queries. It’s a JS framework based on React Redux.
CAUTION: Look at the licensing statements from Facebook. You should not use works from Facebook if you might have a product that might infringe on something Facebook may do in the future, such as any social networking, including IoT.
An alternative is SPARQL used in IoT.
https://dev-blog.apollodata.com/ is based on React Redux, React Native
Apollodata.com/Optics provides metrics: execution traces, field latencies, field usage
Scaphold.io provides a SaaS cloud platform
using either Relay or Apollo starter kits at
https://github.com/scaphold-io
and explained on
their YouTube channel
Bindings
Those who write custom servers communicating in GraphQL would use bindings for:
- Facebook’s Relay
- Flask at https://github.com/graphql-python/flask-graphql
- Django at https://docs.graphene-python.org/projects/django/en/latest/
- MongoDB at https://github.com/graphql-python/graphene-mongo
- SQLAlchemy at https://docs.graphene-python.org/projects/sqlalchemy/en/latest/
- Google App Engine (GAE) at https://docs.graphene-python.org/projects/gae/en/latest/
Bindings
Perform an introspection query. As the GraphQL schema matures, new data types appear.
Make a single call to retrieve (rather than many REST API calls).
Response is structured using the same JSON hierarchy as the call.
Changes can occur with less fuss than REST API.
Clients
-
Visit https://graphene-python.org, the front page for the Python library to build GraphQL APIs.
-
I have that “hello world” code (with added notes) in my repo at:
https://github.com/wilsonmar/python-samples/blob/master/graphql-hello.py
pip install graphene is based on code:
-
When executed, the response from graphene-hello.py is simply:
Whatever world
-
graphene-schema-hello.py from https://docs.graphene-python.org/en/stable/quickstart/ describes each Field in the data model provided by the server using scalar types like String, Int and Enum and compound types like List and Object.
For more details refer to the Graphene Types Reference at https://docs.graphene-python.org/en/stable/types/#typesreference
Referencess about Graphene:
-
https://docs.graphene-python.org/en/stable/
-
https://dev.to/mesadhan/python-flask-graphql-with-graphene-nla
https://www.moesif.com/blog/technical/graphql/Getting-Started-with-Python-GraphQL-Part1/
Post-Graphile is an alternative to Graphene.
https://itnext.io/python-graphql-tips-tricks-and-performance-improvements-beede1f4adb6
Client features
- Query builder
- Cache
- Retry
- Error handling
-
Rollback
- Conditional fetching
- Mutations
- Fragments group commonly used fields and reuses them.
- Optimistic UI
- Pagination
Schema Definition Language (SDL)
GraphQL is a data description language and not a programming language.
GraphQL communicates in a Schema Definition Language (SDL) defined at https://graphql.org/learn/schema
type Query { hello(name: String = "stranger"): String goodbye: String }
Rock Stars
OG GraphQL co-creators at Facebook:
-
Lee Byron (@leeb, leebyron.com)
-
Nicolas Schrock
-
Daniel Schafer
Relay creators at Facebook:
-
Joe Savona (@en_JS)
-
Steven Luscher
-
Greg Hurrell
Meteor Development Group / ApolloData.com / GitHub.com/apollostack
-
CEO Geoff Schmidt (@immir)
-
VP of Product Matt DeBergalis
-
Sashko Stubailo (@stubailo) Slidshare
-
Apollo Services Danielle Man (@danimman)
User GitHub:
- Brandon Black
User Coursera:
-
Brennan Saeta (@bsaeta)
-
Founder Andrew Ng (@AndrewYNg) on Machine Learning
Users:
- Kenton Jacobsen from Conde Nast
- Nick Nance from Credit Karma
- Mike Isman from Hudl
- Aaron Weiker from Concur
PowerShellforGitHubGraphQL module
I couldn’t find a PSGallery module for referencing GitHub’s GraphQL, so I set out to create one when that’s what Karol Kaczmarek suggested I do.
Resources
DataLoader to reduce over-fetching (one record several times)
Neo4j Online Meetup - Creating a GraphQL Api with Neo4j by Mark Needham
More on API Microservices
This is one of a series:
- API Portals
- GraphQL API
- GitHub API
- GitHub GraphQL API
- API Swagger
- API Design Tools
- API Design
- API Programming
- REST API Responses
- API Management Evaluation
- API Management by Microsoft Azure
- API Management by Amazon
- PowerShell GitHub API Programming
- PowerShell API Programming
- PowerShell Desired State Configuration
- PowerShell on Mac