Configuring Relations
When your GraphQL types reference other types (e.g., a Taxonomy has multiple
Discipline objects), you need to configure how TypoGraph should resolve these
relations from your database.
Why Relations Need Configuration
Unlike scalar fields (strings, integers), object-type fields require the TypoGraph extension to:
- Identify which database column stores the relation reference
- Know which table to query for the related records
- Understand the storage format (single UID, comma-separated UIDs, or MM table)
Without explicit configuration, TypoGraph will log a warning and return null
for unconfigured relations.
Relation Configuration Structure
Relations are configured under the typograph. key in the site
configuration, nested as <Type:
typograph:
relations:
TypeName:
fieldName:
sourceField: database_column_name
targetType: RelatedTypeName
storageType: uid # uid | commaSeparated | mmTable | foreignKey
# Additional fields for mmTable storage type:
mmTable: tx_some_mm_table
mmSourceField: uid_local
mmTargetField: uid_foreign
mmSortingField: sorting
# Additional fields for foreignKey storage type:
foreignKeyField: column_in_target_table
Configuration Fields
| Field | Required | Default | Description |
|---|---|---|---|
source | No | Field name in snake_case | Database column in the source table containing the relation reference
(not used for foreign type) |
target | Yes | <none> | GraphQL type name of the related entity (must exist in table) |
storage | No | uid | How the relation is stored: uid, comma, mm, or
foreign |
mm | For mm only | <none> | Name of the MM (many-to-many) intermediary table |
mm | For mm only | uid_ | Column in MM table referencing source record |
mm | For mm only | uid_ | Column in MM table referencing target record |
mm | For mm only | sorting | Column in MM table for sorting order |
foreign | For foreign only | <none> | Column in target table that references the source record UID |
Storage Types
The following variants are available for the storage field.
1. Single UID (uid)
Use when a database column contains a single UID reference.
tx_taxonomy table:
uid: 1
name: "Computer Science"
main_discipline: 42 ← Single UID
type Taxonomy {
name: String
mainDiscipline: Discipline
}
typograph:
relations:
Taxonomy:
mainDiscipline:
sourceField: main_discipline
targetType: Discipline
storageType: uid
2. Comma-Separated UIDs (commaSeparated )
Use when a database column contains multiple UIDs as a comma-separated string.
tx_taxonomy table:
uid: 1
name: "Computer Science"
disciplines: "12,45,78" ← Comma-separated UIDs
type Taxonomy {
name: String
disciplines: [Discipline]
}
typograph:
relations:
Taxonomy:
disciplines:
sourceField: disciplines
targetType: Discipline
storageType: commaSeparated
3. MM Table (mmTable )
Use for many-to-many relations stored via an intermediary MM table.
tx_expert table:
uid: 5
name: "Dr. Smith"
tx_expert_discipline_mm table:
uid_local: 5 ← References expert
uid_foreign: 12 ← References discipline
sorting: 1
tx_discipline table:
uid: 12
name: "Physics"
type Expert {
name: String
disciplines: [Discipline]
}
typograph:
relations:
Expert:
disciplines:
targetType: Discipline
storageType: mmTable
mmTable: tx_expert_discipline_mm
mmSourceField: uid_local
mmTargetField: uid_foreign
mmSortingField: sorting
4. Foreign Key / Inverse Relation (foreignKey )
Use when the target table has a foreign key column pointing back to the source record. This handles 'sloppy MM' scenarios where multiple target records can reference the same source record, potentially with duplicate data. While this ideally should not happen, sometimes you may have to work with legacy databases containing denormalized data, inverse relations where child records point to the parent, or just with cases where somebody couldn't be bothered to set up proper MM tables (every software project has at least one former team member like this).
tx_taxonomy table:
uid: 5
name: "Applied Sciences"
tx_discipline table:
uid: 1
name: "Physics"
discipline_taxonomy: 5 ← Foreign key pointing to taxonomy
tx_discipline table:
uid: 2
name: "Physics" ← Same name, different record
discipline_taxonomy: 5 ← Same taxonomy reference
tx_discipline table:
uid: 3
name: "Chemistry"
discipline_taxonomy: 5 ← Another discipline for same taxonomy
type Taxonomy {
name: String
disciplines: [Discipline]
}
type Discipline {
name: String
}
typograph:
relations:
Taxonomy:
disciplines:
targetType: Discipline
storageType: foreignKey
foreignKeyField: discipline_taxonomy
How it works: In this case, TypoGraph queries the target table (tx_) with a WHERE discipline_ query and returns all matching records (including duplicates).
Complete Configuration Example
This is a complete example with multiple relation types:
typograph:
# Schema files
schemaFiles:
- 'EXT:pkf_website/Resources/Private/Schemas/Query.graphql'
- 'EXT:pkf_website/Resources/Private/Schemas/Taxonomy.graphql'
- 'EXT:pkf_website/Resources/Private/Schemas/Discipline.graphql'
- 'EXT:pkf_website/Resources/Private/Schemas/Expert.graphql'
# Root elements to tables mapping
tableMapping:
disciplines: tx_dmdb_domain_model_discipline
experts: tx_academy_domain_model_persons
taxonomies: tx_dmdb_domain_model_discipline_taxonomy
# Relation configuration
relations:
Taxonomy:
# Single UID relation
mainDiscipline:
sourceField: main_discipline
targetType: Discipline
storageType: uid
# Comma-separated UIDs relation
disciplines:
sourceField: disciplines
targetType: Discipline
storageType: commaSeparated
# Foreign key relation (inverse/legacy MM)
relatedDisciplines:
targetType: Discipline
storageType: foreignKey
foreignKeyField: discipline_taxonomy
Expert:
# MM table relation
disciplines:
targetType: Discipline
storageType: mmTable
mmTable: tx_academy_persons_discipline_mm
mmSourceField: uid_local
mmTargetField: uid_foreign
mmSortingField: sorting
GraphQL Query Example
With the configuration above, you can now query nested relations:
{
experts {
familyName
givenName
disciplines {
name
}
}
}