Skip to content

Stop choosing. SurrealDB launch week, 12-16 October

See what's coming
Course content preview

19: Basic graph relations

The record link method we used a few pages ago is the most straightforward way to make a link. Here is how we created a record link back on page 12:

UPDATE town:riverdale SET libraries = [place:surreal_library];


While straightforward to use, record links are simple connections between records that don't contain any information about the link itself.

But sometimes we might also want information about the link - the relation - between two records. If a library adds a new customer, it would be nice to have a field that shows when the person became a customer, such as SET customer_since = d'2025-02-11'.

And a field like customer_since doesn't belong to person or a place, but to the relation between the two.

To accomplish this, we can use a second type of link called a graph edge. These edges are created and queried using their own syntax that uses arrows.

This arrow syntax is easiest to get used to by thinking about the links and queries we want to make. You can query in one direction using -> arrows to the right:

I want to know...PathPath explanationPossible metadata
...where people workperson->works_at->placeperson to works_at to placeWhen did the person start? How much is the salary?
...which books people likeperson->likes->bookperson to likes to bookHow much does the person like a book?

Or the other direction using <- arrows to the left.

I want to know...PathPath explanationPossible metadata
...who works at a placeplace<-works_at<-personplace to being "worked at" by a personSame as above
...who likes a certain bookbook<-likes<-personbook to being liked by a personSame as above


As the paths show, we aren't dealing with direct links this time, but a table in the middle that has a certain name (like works_at or likes). The table in the middle is a graph edge, which always contains two fields called in and out. The in field is where the ID goes for the record that does something, and the out field for the record goes that has something done to it.

And the table in the middle can contain other fields, just like regular records do.

Now that we have the basics down, we'll start making some graph relations in the next page.

THE PLATFORM

Everything an application and its agents know. Five surfaces, one engine.

IN PRODUCTION

Trusted at scale. Samsung, Nvidia, Verizon, Tencent, and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.
Justin Foley

VP of Engineering, Later

SurrealDB

The context and memory layer for AI agents

Database. Graphs, vectors, documents and relational data in one engine, in a single ACID transaction.
Agent Memory. Connects and retrieves context wherever your data lives, every fact carrying its source.
Cloud. Fully managed, in the cloud provider and region you choose.

Explore with AI

Copyright © 2026 SurrealDB Ltd. Registered in England and Wales. Company no. 13615201

Registered address: 3rd Floor 1 Ashley Road, Altrincham, Cheshire, WA14 2DT, United Kingdom

Trading address: Huckletree Oxford Circus, 213 Oxford Street, London, W1D 2LG, United Kingdom