About GraphQL
GraphQL is an open-source query language for APIs that was developed by Facebook as an alternative to REST API. It was released to the public in 2015 as an open-source project, and is hosted by the Linux Foundation at GraphQL.org.
GraphQL can be regarded as an API query language, where data retrieval is accomplished through the use of queries. The following basic examples taken from Data exchange GraphQL service shows a query sent to server that hosts information about hubs that could be accessed by a user.
Examples
Example 1 - Query
Query
query GetHubs {
hubs {
results {
name
id
}
}
}
Result
{
"data": {
"hubs": {
"results": [
{
"name": "Test Account",
"id": "b.03f98b13-ec95-461b-b945-765f496165c1"
},
{
"name": "Construction Records Testing",
"id": "b.768cae14-76b3-4531-9030-25212dab4e48"
}
]
}
}
}
See this Tutorial on GraphQL queries for more information on queries.
When the schema of the data is known, you can query for and change the information in the exact shape the data is organized. Moreover, you will only fetch the data you need. In contrast, REST APIs respond with a predefined payload, regardless of whether you need all the information or not.
For more information on GraphQL, see: