Hello! I am looking into DGraph for a database for animation or VFX studios. I have a couple questions that may be related, but I’m not 100% sure how to do.
Assuming the types…
type Sequence {
name: string
takes: [Take!]
shots: [Shot!]
}
type Shot {
name: string
takes: [Take!]
}
union TakeParent = Shot | Sequence
type Take {
parent: TakeParent!
version: int!
}
Question 1
I want it so that any Take
associated to a Shot
is uniquely versioned. For example, if there is Shot010
and Shot020
, and each of those have 3 versions each, and if I run a query like:
query {
q(func: type("Shot")) {
name
takes {
version
}
}
}
I want a result like this:
[
{
"name": "Shot010",
"takes": [
{
"version": 1
},
{
"version": 2
},
{
"version": 3
}
]
},
{
"name": "Shot020",
"takes": [
{
"version": 1
},
{
"version": 2
},
{
"version": 3
}
]
}
]
I tried wrapping my head around upserts, but I think I’m not implementing it right. I tried something like this:
upsert {
query {
q(func: uid("0x8")) {
e as uid
takes {
t as val(func: max(version)) {
v as version
}
}
}
}
mutation {
set {
uid(t) <dgraph.type> "Take" .
uid(t) <parent> uid(e) .
uid(t) <version> val(v) .
}
}
}
But it looks like my syntax is off. So, my question is I guess two parts. How do I do this in DQL, and how (if possible) can I do this in GraphQL while making the version increment strictly unique for each take per shot?
Question 2
Similar to question 1, but I want each shot to be unique for each sequence. So, if I have a list of sequences like this:
[
{
"name": "Sequence010",
"shots": [
{
"name": "Shot010"
},
{
"name": "Shot020"
}
]
},
{
"name": "Sequence020",
"shots": [
{
"name": "Shot010"
},
{
"name": "Shot020"
}
]
}
]
And I tried to add a shot called Shot010
to either sequence, then how can I make the database throw an error and rollback the change?
Thanks for your help!