GraphQL
GraphQL is an open-source data query language and data manipulation language for APIs, and a query runtime engine.
![]() | |
Developer(s) | Meta, and community |
---|---|
Initial release | September 14, 2015 |
Stable release | October 2021[1]
|
Repository | github |
Written in | Implementations in Java, JavaScript, Ruby, Scala, others. |
Website | graphql |
History
Facebook (now Meta) started GraphQL development in 2012 and released it in 2015.[2] GraphQL was moved on 7 November 2018 to the newly established GraphQL Foundation, hosted by the non-profit Linux Foundation.[3][4]
On 9 February 2018, the GraphQL Schema Definition Language (SDL) became part of the specification.[5]
Design
GraphQL provides a web API approach in which clients define the structure of the data to be returned by the server. This can impede web caching of query results. GraphQL does not provide a full-fledged graph query language such as SPARQL, or even in dialects of SQL that support transitive closure. For example, a GraphQL interface that reports the parents of an individual cannot return, in a single query, the set of all their ancestors.
GraphQL consists of a type system, query language and execution semantics, static validation, and type introspection. It supports reading, writing (mutating), and subscribing to changes to data (realtime updates – most commonly implemented using Websockets).[6] GraphQL servers are available for multiple languages. The result of a single query is returned in JSON format.
Example
POST request:
{
orders {
id
productsList {
product {
name
price
}
quantity
}
totalAmount
}
}
Response:
{
"data": {
"orders": [
{
"id": 1,
"productsList": [
{
"product": {
"name": "orange",
"price": 1.5
},
"quantity": 100
}
],
"totalAmount": 150
}
]
}
}
Testing
GraphQL APIs can be tested manually or with automated tools issuing GraphQL requests and verifying the correctness of the results. Automatic test generation is also possible.[7] New requests may be produced through search-based techniques.[8]
Software for testing includes Step CI.[9]
References
- "GraphQL October 2021 Release Notes". GitHub.
- "GraphQL: A data query language". 14 September 2015.
- "Facebook's GraphQL gets its own open-source foundation". TechCrunch. Retrieved 7 November 2018.
- "The Linux Foundation Announces Intent to Form New Foundation to Support GraphQL - The Linux Foundation". The Linux Foundation. 6 November 2018. Retrieved 17 March 2023.
- "GraphQL SDL included in Github repository". GitHub.
- "GraphQL". facebook.github.io. Facebook. Archived from the original on 18 July 2018. Retrieved 4 July 2018.
- Vargas, D. M.; Blanco, A. F.; Vidaurre, A. C.; Alcocer, J. P. S.; Torres, M. M.; Bergel, A.; Ducasse, S. (2018). "Deviation Testing: A Test Case Generation Technique for GraphQL APIs". 11th International Workshop on Smalltalk Technologies (IWST): 1–9.
- Karlsson, Stefan; Causevic, Adnan; Sundmark, Daniel (May 2021). "Automatic Property-based Testing of GraphQL APIs". 2021 IEEE/ACM International Conference on Automation of Software Test (AST). Madrid, Spain: IEEE: 1–10. arXiv:2012.07380. doi:10.1109/AST52587.2021.00009. ISBN 978-1-6654-3567-3. S2CID 229156477.
- "Testing GraphQL APIs". Step CI Documentation. Retrieved 8 January 2023.