Relationships
When you define foreign keys in your schema, Revisium auto-generates relationship resolvers in the GraphQL API. Related data is resolved automatically in queries.
Single Foreign Key
A field with "foreignKey": "table-name" becomes a nested object in GraphQL:
- Schema
- Query
{
"type": "object",
"properties": {
"title": { "type": "string", "default": "" },
"category": {
"type": "string",
"default": "",
"foreignKey": "categories"
}
},
"required": ["title", "category"]
}
query GetProduct($id: String!) {
product(id: $id) {
data {
title
category {
name
slug
}
}
}
}
Array Foreign Key
An array of FK strings resolves to an array of objects:
- Schema
- Query
{
"type": "object",
"properties": {
"title": { "type": "string", "default": "" },
"tags": {
"type": "array",
"items": {
"type": "string",
"default": "",
"foreignKey": "tags"
}
}
},
"required": ["title", "tags"]
}
query GetArticle($id: String!) {
article(id: $id) {
data {
title
tags {
name
color
}
}
}
}
FK in Array of Objects
Foreign keys inside nested array objects are also resolved:
- Schema
- Query
{
"type": "object",
"properties": {
"title": { "type": "string", "default": "" },
"translations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"language": {
"type": "string",
"default": "",
"foreignKey": "languages"
},
"content": { "type": "string", "default": "" }
},
"required": ["language", "content"]
}
}
},
"required": ["title", "translations"]
}
query GetArticle($id: String!) {
article(id: $id) {
data {
title
translations {
content
language {
name
code
}
}
}
}
}
Key Points
- Foreign keys are always declared as
"type": "string"with"foreignKey": "table-name"in the JSON Schema - Relationship resolvers are generated automatically — no additional configuration
- FK values must be valid
rowIdvalues in the referenced table - There are no automatic reverse relationships — only explicitly declared foreign keys become queryable
- Relationship data is fully resolved when queried (no sub-filtering on related data)