user
| Column | Type
----------|-------
| id | character varying
| name | character varying
profile
| Column | Type
----------|-------
| id | character varying
| avatar | character varying
| userId | character varying FOREIGN KEY UNIQUE CONSTRAINT
One-To-Many (1:n) Relationships
In One-To-Many relation, one entity instance is related to multiple instance of the other entity.
Database table for the Post entity:
The only difference between 1:1 and 1:n is the unique constraint that 1:1 has.
Many-To-Many (n:n) Relationships
Many-To-Many is a relationship where one entity instance is related to many instance of other entity and vice-versa. In this relationship one side of the relation must derive.
A junction table is created for n:n relationship.
Database tables:
Reverse Lookups
Defining reverse lookups on an entity allows you to query other side of the relation. Use @derivedFrom directive to add reverse lookup to an entity.
Example If we want to access a user's posts from the user entity we should add a derived field to User entity:
Relationships In Mappings
Each GraphQL entity has a corresponding typeorm entity and we use these entities to perform CRUD operations.