More query languages
Three more languages, each with its own idea.
SPARQL
SPARQL (said "sparkle") queries RDF triple stores. Variables start with a question mark, like ?person. A path such as :livesIn / :partOf* follows one livesIn edge, then partOf edges zero or more times. Properties and edges are both predicates in RDF, so one pattern style matches both. SPARQL is older than Cypher, and Cypher borrowed its pattern matching from it.
Datalog facts and rules
Datalog comes from 1980s research and is a subset of Prolog. It is relational, not a graph model: data is facts, each a row in a table, like part_of(Leeds, England). A rule defines a virtual table, like a SQL view. Left of :- is the new table; right of it are patterns that must all match.
Recursive Datalog
A rule may refer to itself. "A is inside P if A is part of B and B is inside P" climbs a hierarchy one level per step. A base rule, like "every place is inside itself", gives it a place to start. You build a query from small rules that use each other, like functions calling functions.
GraphQL's purpose and limits
GraphQL lets a phone app or web page ask for exactly the fields its screen needs. Queries come from untrusted clients, so it has no recursion and no free-form search. It needs tooling to map queries onto backend services.
GraphQL response shape
The JSON answer mirrors the query. It repeats data on purpose, like an author's name on every comment, to save extra requests. The database can stay normalized; the server fills in names from IDs. Clients can only follow links the schema declares. GraphQL can sit on any database.
Remember
- SPARQL variables start with ?; a star means zero or more steps.
- Datalog rules make virtual tables when all patterns match.
- A recursive rule needs a base rule to start.
- GraphQL has no recursion, because clients are untrusted.
- GraphQL responses repeat data on purpose.