Data types, Schema and Type System

It’s time to talk about data types and nodes

Type System

Starting in version 1.1, Dgraph has support for a type system. At the moment, the type system is basic but can be used already to categorize nodes and query them based on their type. The type system is also used during expand queries.

So in order to Expand or Delete nodes. You need to define your Types correctly. You can see in detail more about the Type System here.

Data types and Schema

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 identifiers 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 Dgraph:  http://localhost:8080  
Response