Contents
What is GraphQL?
GraphQL ("Graph Query Language") is a specification for a query language that was created by Facebook in 2012 for internal use and publicly open sourced in 2015. It is specifically focused on API development ("A query language for your API") and serves as an alternative to REST-based architectures.
Since GraphQL is only a syntax that describes how to ask for data, the user can decide between various implementations in different programming languages, almost all of which use JSON to access data. You can find a list containing some of the most popular libraries and services here.
Contrary to what the name implies, GraphQL has nothing to do with graph databases like Wikidata or Neo4j. The word "graph" in the name comes from the idea of crawling across the API graph. GraphQL is not tied to a specific schema or structure of the database. It is much less powerful than other query languages and not designed for exploiting the rich semantics of expressive ontologies.
Clients specify the data they need, receiving only what they ask for and nothing more. Thus, it minimizes the amount of data transferred and is particularly useful for mobile apps and websites.
GraphQL serves as a framework for defining your own query language on JSON-like data. GraphQL allows users to define the shape (the "schema") of data that they want to be accessible. This schema defines the semantics and the structure of the queries that are allowed.
Example Query
A query in GraphQL is essentially a JSON without the values. The values are then added in the result. For example:
{ chair { name lectures { title language } } }
This query might return something like
{ "chair": { "name": "Chair of algorithms and data structures" "lectures": [ { "title": "Programmieren in C++" "language": "German" } { "title": "Information Retrieval" "language": "English" } { "title": "Algorithmen und Datenstrukturen" "language": "German" } ] } }
TODO: Explain more how queries work and how the schema is defined.
GraphiQL
The GraphQL foundation also provides GraphiQL, a graphical interactive in-browser GraphQL IDE for editing and testing queries. GraphiQL offers syntax highlighting, autocompletion, a documentation explorer, query history and other features. Again, there are libraries in various languages to choose from.
TODO: Set up a docker container to build a GraphiQL example to play around with.