Level up your GraphQL + GraphDB knowledge - Register free for Dgraph Day
To optimize your experience, the interactive tutorial is only available on desktop.

Dgraph GraphQL Tour

Basic

Data types, Schema and Type System

It’s time to talk about data types and scalars.

Type System

A GraphQL API is a strictly-typed API. Every node is required to have a specific type. A GraphQL API built with Dgraph does some “magic” for you so, when you add data it assigns types, and it makes it easy to filter by types when querying data.

You might have noticed from Load Data that the data in triple format includes a predicate for <dgraph.type>. The values from these predicates match the GraphQL type definition of the node. If you load the data using Bulk Loader, Live Loader, or DQL mutations, you will need to set these type predicates if you want the node to be accessible through the GraphQL API.

Data types and schema

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

The GraphQL schema tells us how to interpret every field. Run the example introspection query and have a look at the JSON result.

There are two kinds of fields in a graph: nodes and values (or literals). In the example, nodes representing people have a name field with a string value and an age field to an int value. They also have edges that connect to other nodes. A value can’t have any edges coming out of it.

Here are the types available to store values in Dgraph:

Dgraph Type Description
ID Unique Identifier (UID)
Int signed 32-bit integer
Int64 signed 64-bit integer
Float double-precision floating-point number
String string
Boolean Boolean
DateTime RFC3339 time format with optional timezone like: 2006-01-02T15:04:05.999999999+10:00 or 2006-01-02T15:04:05.999999999
Point Geolocation types (see docs)
PointList Geolocation types (see docs)
Polygon Geolocation types (see docs)
MultiPolygon Geolocation types (see docs)

The schema tells us the Person type has a friends field that goes from one node of type Person to another node (also of type Person) but not to a value.

There’s a lot more to learn about schemas later in the tutorial. For now, though, you know enough about schemas to better understand the structure of our graph and the types of nodes and values included in its dataset.