Wilson Mar bio photo

Wilson Mar

Hello!

Calendar YouTube Github

LinkedIn

Now THIS is the industry standard. REST API is so last season.

US (English)   Norsk (Norwegian)   Español (Spanish)   Français (French)   Deutsch (German)   Italiano   Português   Estonian   اَلْعَرَبِيَّةُ (Egypt Arabic)   Napali   中文 (简体) Chinese (Simplified)   日本語 Japanese   한국어 Korean

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:

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

  1. Visit https://graphene-python.org, the front page for the Python library to build GraphQL APIs.

  2. 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:

    https://github.com/graphql-python/graphene

  3. When executed, the response from graphene-hello.py is simply:

    Whatever world
  4. 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.

PowerShell for GitHub GraphQL

Resources

The Awesome list for GraphQL

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: