---
title: "9: Graph dependencies | SurrealDB University"
description: "RELATION tables depends_on and activity_of, RELATE, and COMPUTED followed_by."
url: https://surrealdb.com/learn/schemas/page-09
---

![Course content preview](https://surrealdb.com/assets/static/course-schemas.D4CFbBhP.avif)

[Back to Courses](https://surrealdb.com/learn)

Course chapters

[Schema internals and migrations](https://surrealdb.com/learn/schemas) Internals [1: Schemaless vs. schemafull](https://surrealdb.com/learn/schemas/page-01) [2: Schema internals](https://surrealdb.com/learn/schemas/page-02) [3: Migrations](https://surrealdb.com/learn/schemas/page-03) [4: Data types](https://surrealdb.com/learn/schemas/page-04) [5: Automation](https://surrealdb.com/learn/schemas/page-05) Migrations [6: SurrealKit and the first table](https://surrealdb.com/learn/schemas/page-06) [7: Activities and seed data](https://surrealdb.com/learn/schemas/page-07) [8: Computed and asserted fields](https://surrealdb.com/learn/schemas/page-08) [9: Graph dependencies](https://surrealdb.com/learn/schemas/page-09) [10: Sync vs rollouts](https://surrealdb.com/learn/schemas/page-10) [11: Milestones](https://surrealdb.com/learn/schemas/page-11) [12: People and indexes](https://surrealdb.com/learn/schemas/page-12) [13: Events and CI](https://surrealdb.com/learn/schemas/page-13) [14: Capstone](https://surrealdb.com/learn/schemas/page-14)

# 9: Graph dependencies

Project schedules are inherently a graph: activities depend on other activities, and activities belong to projects. SurrealDB models that with `RELATION` tables and `RELATE`, not just `record<>` fields.

This chapter uses `watch`, so each schema save applies without you running another one-shot sync. Start it in a separate terminal before making any changes:

```bash
surrealkit sync --watch --user root --pass secret --ns main --db main
```

Leave it running while you add the files below. Stop it with Ctrl+C once you reach the checkpoint, before part [10](https://surrealdb.com/learn/schemas/page-10)’s rollout material.

## `depends_on`: activity → activity

Create the file `database/schema/depends_on.surql` and add the following:

```surql
DEFINE TABLE depends_on SCHEMAFULL TYPE RELATION IN activity OUT activity;
```

This edge means "the `out` activity has to finish before the `in` activity can start".

Run this edge now in SurrealDB Studio or `surreal sql`, and append the same line to `database/seed/demo_project.surql` for the next fresh `seed`. Re-running `surrealkit seed` would replay the whole file and fail on the existing `CREATE` records (part [7](https://surrealdb.com/learn/schemas/page-07)).

```surql
RELATE activity:concrete->depends_on->activity:kickoff;
```

SurrealDB Studio's designer can create `RELATION` tables too (part [2](https://surrealdb.com/learn/schemas/page-02)); here we keep them in schema files for SurrealKit.

## `activity_of`: activity → project

Create `database/schema/activity_of.surql` and add the following:

```surql
DEFINE TABLE activity_of SCHEMAFULL TYPE RELATION IN activity OUT project;
```

Same pattern: run the links now, and append them to `database/seed/demo_project.surql` for the next from-scratch seed.

```surql
RELATE activity:kickoff->activity_of->project:one;
RELATE activity:concrete->activity_of->project:one;
```

## COMPUTED `followed_by` (backlinks)

The docs sample exposes dependents through a graph `COMPUTED` field:

```surql
DEFINE FIELD followed_by ON activity COMPUTED <-depends_on<-activity;
```

Add this line to `activity.surql` and save; `watch` should re-sync within a few seconds.

The edge was `RELATE activity:concrete->depends_on->activity:kickoff`, so `kickoff` is the dependency and `concrete` depends on it. Traversal `<-depends_on<-activity` walks inbound `depends_on` edges: from an activity, it finds records that point *at* it. Query the dependency, not the depender:

```surql
SELECT name, followed_by.{ name, progress } FROM activity:kickoff;
```

That returns `concrete` under `followed_by`: activities that follow after kickoff (that list kickoff as a dependency). The same field on `activity:concrete` is empty until something depends on concrete. This is the project-planning version of "computed backlinks" from the sketch pages: graph traversal declared right in the schema.

## Graph queries

```surql
-- Dependencies leaving an activity
SELECT ->depends_on->activity.{ name, start, end } FROM activity:concrete;

-- Everything tied to a project
SELECT
    name,
    ->activity_of->project AS project,
    ->depends_on->activity AS depends_on
FROM activity;
```

For larger graphs, add indexes in part [12](https://surrealdb.com/learn/schemas/page-12) to support range and lookup patterns.

## RELATION vs record field

| Approach | When to use |
| --- | --- |
| `record<project>` on `activity` | Simple foreign key, one project per record |
| `activity_of` `RELATION` | Explicit graph, multiple routing queries, edge metadata later |
| Both | Valid during expand migrations; pick one canonical model and contract the other (parts [10](https://surrealdb.com/learn/schemas/page-10)–[11](https://surrealdb.com/learn/schemas/page-11)) |

The docs sample uses `RELATE` for membership, and this course follows that.

## Checkpoint

- `depends_on` and `activity_of` `RELATION` tables in schema files
- Seed data uses `RELATE`
- `COMPUTED` `followed_by` for successor lookup (who depends on this activity)

When the graph looks right, stop `watch` with Ctrl+C so the terminal is free for part [10](https://surrealdb.com/learn/schemas/page-10)’s rollout material (then milestones in part [11](https://surrealdb.com/learn/schemas/page-11)).

Next: sync vs rollouts, why shared databases need a different SurrealKit command, then milestones that roll up activity `progress`.

Previous

8: Computed and asserted fields

[Previous](https://surrealdb.com/learn/schemas/page-08)

Next lesson

10: Sync vs rollouts

[Next lesson](https://surrealdb.com/learn/schemas/page-10)

```json
{"@context":"https://schema.org","@type":"Course","name":"Schema internals and migrations","description":"Learn how SurrealDB stores schema metadata, how DEFINE statements shape your database, and how to migrate production data safely.","url":"https://surrealdb.com/learn/schemas","inLanguage":"en","isAccessibleForFree":true,"provider":{"@type":"Organization","name":"SurrealDB","url":"https://surrealdb.com"},"hasPart":[{"@type":"LearningResource","name":"Schema internals and migrations","url":"https://surrealdb.com/learn/schemas"},{"@type":"LearningResource","name":"1: Schemaless vs. schemafull","url":"https://surrealdb.com/learn/schemas/page-01"},{"@type":"LearningResource","name":"2: Schema internals","url":"https://surrealdb.com/learn/schemas/page-02"},{"@type":"LearningResource","name":"3: Migrations","url":"https://surrealdb.com/learn/schemas/page-03"},{"@type":"LearningResource","name":"4: Data types","url":"https://surrealdb.com/learn/schemas/page-04"},{"@type":"LearningResource","name":"5: Automation","url":"https://surrealdb.com/learn/schemas/page-05"},{"@type":"LearningResource","name":"6: SurrealKit and the first table","url":"https://surrealdb.com/learn/schemas/page-06"},{"@type":"LearningResource","name":"7: Activities and seed data","url":"https://surrealdb.com/learn/schemas/page-07"},{"@type":"LearningResource","name":"8: Computed and asserted fields","url":"https://surrealdb.com/learn/schemas/page-08"},{"@type":"LearningResource","name":"9: Graph dependencies","url":"https://surrealdb.com/learn/schemas/page-09"},{"@type":"LearningResource","name":"10: Sync vs rollouts","url":"https://surrealdb.com/learn/schemas/page-10"},{"@type":"LearningResource","name":"11: Milestones","url":"https://surrealdb.com/learn/schemas/page-11"},{"@type":"LearningResource","name":"12: People and indexes","url":"https://surrealdb.com/learn/schemas/page-12"},{"@type":"LearningResource","name":"13: Events and CI","url":"https://surrealdb.com/learn/schemas/page-13"},{"@type":"LearningResource","name":"14: Capstone","url":"https://surrealdb.com/learn/schemas/page-14"}]}
```

```json
{"@context":"https://schema.org","@type":"LearningResource","name":"9: Graph dependencies","description":"RELATION tables depends_on and activity_of, RELATE, and COMPUTED followed_by.","url":"https://surrealdb.com/learn/schemas/page-09","learningResourceType":"lesson","isPartOf":{"@type":"Course","name":"Schema internals and migrations","url":"https://surrealdb.com/learn/schemas"},"position":12}
```

```json
{"@context":"https://schema.org","@type":"Organization","name":"SurrealDB","url":"https://surrealdb.com","logo":"https://surrealdb.com/assets/static/logo.BG7_TG2b.svg","description":"SurrealDB is the unified data layer for AI. A multi-model database for documents, graphs, vectors, and time-series.","foundingDate":"2022","legalName":"SurrealDB Ltd","identifier":{"@type":"PropertyValue","propertyID":"GB-COH","value":"13615201"},"address":{"@type":"PostalAddress","streetAddress":"3rd Floor, 1 Ashley Road","addressLocality":"Altrincham","addressRegion":"Cheshire","postalCode":"WA14 2DT","addressCountry":"GB"},"contactPoint":[{"@type":"ContactPoint","contactType":"customer support","email":"support@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"sales","email":"info@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"security","email":"security@surrealdb.com","url":"https://surrealdb.com/.well-known/security.txt","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"legal","email":"legal@surrealdb.com","url":"https://surrealdb.com/legal","availableLanguage":"English"}],"hasCertification":[{"@type":"Certification","name":"SOC 2 Type 2"},{"@type":"Certification","name":"GDPR"},{"@type":"Certification","name":"Cyber Essentials Plus"},{"@type":"Certification","name":"ISO 27001"}],"owns":[{"@type":"SoftwareApplication","name":"SurrealDB","url":"https://surrealdb.com/surrealdb"},{"@type":"SoftwareApplication","name":"Agent Memory","url":"https://surrealdb.com/agent-memory"}],"knowsAbout":["multi-model databases","document databases","graph databases","vector search","time-series databases","SurrealQL","Agent Memory","real-time databases","embedded databases","context layer","graph ontology","distributed database","knowledge graphs","distributed transaction protocols","highly-scalable databases"],"sameAs":["https://www.wikidata.org/wiki/Q124316308","https://github.com/surrealdb/surrealdb","https://twitter.com/surrealdb","https://www.youtube.com/@surrealdb","https://www.linkedin.com/company/surrealdb","https://discord.gg/surrealdb","https://www.reddit.com/r/surrealdb","https://www.instagram.com/surrealdb","https://medium.com/surrealdb","https://dev.to/surrealdb"]}
```

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://surrealdb.com"},{"@type":"ListItem","position":2,"name":"Learn","item":"https://surrealdb.com/learn"},{"@type":"ListItem","position":3,"name":"Page 09","item":"https://surrealdb.com/learn/schemas/page-09"}]}
```
