Data types and Schema

It’s time to talk about data types and nodes

There was some magic in the last query because some of the queried edges returned a value (name and age), but some were edges to other nodes (friend and owns_pet) that themselves had further properties.

The truth is that there is a schema to tell us how to interpret an edge.

The visualization won’t be much use this time. Have a look at the JSON to find out about the schema of the example.

There are two kinds of nodes in a graph, let’s call them nodes and values (or literals). In the example, nodes representing people have a name edge to a string value and an age edge to an int value. A value can’t have any edges coming out of it.

Here are the types you can use to store values in Dgraph.

Dgraph Type Description
int signed 64 bit integer
float double precision floating point number
string string
bool boolean
id ID’s stored as strings
dateTime RFC3339 time format with optional timezone eg: 2006-01-02T15:04:05.999999999+10:00 or 2006-01-02T15:04:05.999999999
geo geometries stored using go-geom

There’s also the uid type, for nodes. The schema tells us the friend edge goes from one node to another, but not to a value.

There’s lots more about schema later in the tutorial. For now, though, we know more about the structure of our graph and the types of things in it.

Endpoint: /query