Example:
Two types of nodes, “Job” and “JobStatus”.
JobStatus stores information about a job’s status.
So it would be a 1 to 1 relationship.
- Is there any way to enforce a one to one relationship in the schema (graphQL/dgraph)?
- Is it possible to make it so each upsert/mutation of a Job’s jobStatus only modifies that one jobStatus (and doesn’t create another jobStatus) (without having to do uid shenanigans)?
There is.
Example:
enum Tag {
...
}
type Post {
...
// An array syntax signifies one to many relation,
// so a Post can have as many tags as needed.
tags: [Tag!]!
}
However, if you remove array syntax then:
enum Tag {
...
}
type Post {
...
tags: Tag! // Non array syntax signifies, 1 to 1 relationship.
}
P.S. If I remember correctly, you can specify UID type as an Array in Ratel UI Schema.
3 Likes
Oh thanks!
If I have a one to one relationship with another type
type Tag {
...
}
type Post {
...
tag: Tag! // Non array syntax signifies, 1 to 1 relationship.
}
if I do a mutation of the Tag associated with Post, will the other Tag be overwritten, or will a new Tag be created and the old one will linger in the system
Mutation means 3 operations, Create, Update & Delete.
Update will overwrite, Create will generate a new one and the old one will linger in the system.