Dive into GraphQL with Python: What is GraphQL and Graphene?
So… To begin with, I want to say that GraphQL is not a library or framework! It is just a specification which was officially published by Facebook in 2015.
Here is introduction from this standard:
This is a Draft RFC Specification for GraphQL, a query language created by Facebook in 2012 for describing the capabilities and requirements of data models for client‐server applications. The development of this standard started in 2015. GraphQL is a new and evolving language and is not complete. Significant enhancement will continue in future editions of this specification.
GraphQL — simple query language, which helps you to get exactly that data, what you need, describe your own data types and to scale your API without any headache :)
In GraphQL ecosystem are three main classes:
Query — way to fetch data in a read-only manner from your GraphQL API (analogy of GET request in REST API).
Mutation — way to change(create/update/delete) data on your server (analogy of POST request in REST API).
Subscription — way to get a real-time feed of data from your server (something like traditional Web Sockets).
For example, someone clapped your post on Medium, while you watched the same post, and you received notification “Someone clapped your post!” As a result, counter of claps automatically updated without page reloading.
What is schema?
Supported data types in GraphQL: Scalars(Int, Float, String, Boolean, ID), List, Enum, Non-null and others…
You can find out more info about data types here.
What is the difference between GraphQL and REST?
The main point for me — JUST ONE ENDPOINT FOR REQUESTS!!! It is a big pleasure, when you realize you should not think about something like this: “How I should name this endpoint?” It is a waste of time! With a help of GraphQL you create a schema and write a query to an only route.
Main reasons why GraphQL is better:
1) this is a clear and simple API between the backend and the frontend;
2) you are not obliged to write documentation for API;
3) reducing communication costs, less connections;
4) no API versioning;
5) just a great tool for your API;
What is Graphene?
Graphene — simple Python framework for GraphQL which also is pluggable with Django, Flask, SQLAlchemy and Google App Engine. It is under active development.
I am using this framework in my current project with Flask. So, in next topics about Graphene I’m going to explain how to create queries/mutations, own schemas, data types, how to resolve data from database and other stuff.
I hope you appreciated the first part of this topic about GraphQL and Graphene and I expect to see a lot of claps %)