Graql enables users to write queries against a Grakn knowledge graph leveraging the inherent semantics of the data. Concepts can be retrieved by specifying the patterns of types and relationships that identify them. Graql is declarative and therefore it handles the optimisation of the knowledge graph queries needed to retrieve information.
A variable is an identifier prefixed with a dollar
$. Valid identifiers must comprise of one or
more alphanumeric characters, dashes and underscores.
match $x isa $A; $A label person; get;
should be written more succinctly as
match $x isa person; get;
An attribute’s value is constrained by the datatype of its type:
long- a 64-bit signed integer
double- a double-precision floating point number, including a decimal point.
string- enclosed in double
" "or single
date- a date or a date-time, in ISO 8601 format
There are seven types of queries, which are begun with the following keywords:
- get - for getting concepts from the knowledge graph
- aggregate - for transforming data in the knowledge graph
- define - for defining schema concepts
- undefine - for removing schema concepts
- insert - for inserting data
- delete - for deleting data
- compute - for computing useful information about your knowledge graph
The following list Graql’s reserved keywords:
Querying and query modifiers
aggregate, asc by compute, contains delete, desc, distinct from id, in, insert label, limit match offset, order regex select to val
datatype boolean, double, long, string, date true, false
has, is-abstract, isa, key, plays, relates
count group max, mean, median, min std, sum
and concat do else, elseif for if, in noescp, not, null true, false
If you are already familiar with Graql, you may find our cheatsheet reference a helpful page to bookmark or print out!