Graph Query Language, API that allows client to define the structure of the data they want actually
Graphql follows all 6 constrant of RestAPI. It takes approach of being query-centric because it is structured to functions similarly to a database query language like SQL
Find URL where hosted & Submit authorized req. that contains query parameter as body of POST req. to access GraphQL API.
like :-
query{
users{
username
id
email
}
}
REQ.
{
"data":{
"users":{
"username":hapi_hacker
"id":1111
"email":[email protected]
}
}
} RES.
In Graphql Request, the body of the POST req. is what the provider process

In Below Example, GraphQL req. & res. depicting a req. to check store’s inventory of graphic card
POST /graphql HTTP/1.1
HOST: graphql-shop.com
Authorization: Bearer ab4dtok3n
{query1️⃣{
inventory2️⃣{(item:"Graphics Card"){
name
fields3️⃣{
price
quantity
}
} REQ.
}
}
HTTP/1.1 200 OK
Content-type: application/json
Server: GraphqlServer
{"data":{
"inventory":{
"name":"Graphics Card",
"fields":4️⃣[
"price":"999.99"
"quantity":25
}
]
}
}
} RES.
unlike GraphQL consumers REST API needs to filter out the data if consumer only need to a specific value but
As you See In the Above Example :-
1️⃣, which is equivalent to GET req. & used to obtain info. from API
2️⃣, is also known as root query type
3️⃣, similar to key/ value pair in REST. The main difference is that we can specify the specif field we are looking for
4️⃣, Instead of getting item ID, item name, and other superfluous info. , The Query resolved with only field we needed
GraphQL uses 3 operations within the POST request to interact with GraphQL APIs: query, Mutation & Subscription.
GraphQL uses Schemas, a collection of the data that can be queries with the given service. Having Access to the GraphQL schemas similar to having access to a REST API collection.
A Graphql schema will provide you with the information you’ll need in order to query the API.
API Uses several formats to facilitate the exchange of data.
We will talk about 3 Common Format : JSON, XML, YAML
Javascript Object Notation is primary data interchange format widely used in APIs
JSON Represents objects as key/value pairs separated by commas,
with the pair of curly brackets
{
"firstname":"Jason",
"lastName":"haddix",
"platform":"twitter",
"Followers":124400,
"footboller":false,
"hobbies":"gaming",
"isbughunter":true,
"experience":["bug hunting","Security Consultant","Penetration tester"]
}
Json doesn’t allow inline comment, any sort of comment-like communication must take place as a key/value pair like “comment” : “This is a comment”