Dgraph DQL Tour
Data types, Schema and Type System
It’s time to talk about data types and nodes.
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 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 (
age), but some were edges to other nodes
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.
||default type (It is a neutral type)|
||signed 64 bit integer|
||double precision floating-point number|
||RFC3339 time format with optional timezone eg: 2006-01-02T15:04:05.999999999+10:00 or 2006-01-02T15:04:05.999999999|
||geometries stored using go-geom|
There’s also the
uid type, for nodes. The schema tells us the
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.