What is a REST API? REST stand for Representational state transfer (REST) or RESTful web services and it's the most used tipe of API you find online.
If I need some data I need to go to the url of the API and go to the subpath of the data I want.
For example if I need some posts from _https://jsonplaceholder.typicode.com/_ I need to go to _https://jsonplaceholder.typicode.com/posts_ and download all the posts or pass the id in the url like in _https://jsonplaceholder.typicode.com/posts/1_. Some time I will need only fews posta but the api give me all or one so it's can be some heavy lifting for the connection. And I need to know all the url and the params needed for the datas.
This is why Facebook in 2012 develop GraphQL
#What is GraphQL
GraphQL is a data query language which request a knowledge about the schema of the api.
One of the best “skill” of GraphQL is the multi-db support. You can map multiple database in one api because the graphql server can use multiple source for build the api, and, doing so, add different's types of db or other type of source at the same time.
In this way you can use with one unique and uniform interface hidding behind it all the architectural dectail with only one point of comunication (the graphql url) with all the user need from the api.
Structure of a GraphQL API
If you want a GraphQL's API you need to know how the API works.
All the data into the databases are object named Type with multiple Field. Every Field is get by a Resolvers which return a Value.
You will need a Schema, a collection of Types, for describing all the api and make the api working.
You also need to know the difference between Query and Mutation because there are the only action youi can make on a GraphQL API.
A Query is a type of the schema for getting out the datas you will need for your work.
A Mutation is a type of the schema for adding or editing the datas in the databases.
#Why use a GraphQL over Rest ?
Which is the difference between Rest API and a GraphQL API? Because you can get only what you want and nothing more.
This will be usefull because some type of Query will be resized than the SQL query and you will be writing in a GraphQL language which check for type error and syntactic error and output error if the Query or the Mutation don't respect the Schema. In this way the Api Admin will allways be in controll of all the operation on the database and the user must be allways knew all the change into the Schema
In this way you will have an api with only what you need for your lightnet app which use only the necessary connection, no more.
Now I'm working on an another article about the python implementation of GraphQL so wait another article.
by Fundor 333