Querying Grakn Schema using Graql

The schema can be queried using the match clause A match describes a pattern to find in the knowledge graph, and the following properties only apply to schema types.

sub

Match types that are a subclass of the given type.


match $x sub thing; get; # List all types
match $x sub attribute; get; # List all attribute types
match $x sub entity; get; # List all entity types
match $x sub role; get; # List all role types
match $x sub relationship; get; # List all relationship types


qb.match(var("x").sub("thing")).get();

relates

Match roles to a given relationship.


match parentship relates $x; get;


qb.match(label("parentship").relates(var("x"))).get();

as

Match hierarchy of roles in relates.


match fatherhood relates $x as parent; get;


qb.match(label("fatherhood").relates(var("x"), label("parent"))).get();

plays

Match types that play the given role.


match $x plays child; get;


qb.match(var("x").plays("child")).get();

has

Match types that can have the given attribute.


match $x has firstname; get;


qb.match(var("x").has("firstname")).get();

The above is equivalent to:


match $x plays @has-firstname-owner; get;


qb.match(var("x").plays("has-firstname-owner")).get();

label

Allows you to refer to a specific types by its typename. For example:

match $x isa $type; $type label 'person'; get $x;

This is equivalent to the following:

match $x isa person; get;
Tags: graql