Clarifying my understanding of the @upsert directive

From your docs

Upsert directive
Predicates can specify the @upsert directive if you want to do upsert operations against it. If the @upsert directive is specified then the index key for the predicate would be checked for conflict while committing a transaction, which would allow upserts.

This is how you specify the upsert directive for a predicate. This replaces the IgnoreIndexConflict field which was part of the mutation object in previous releases.

email: string @index(exact) @upsert .

Reading through the docs, it seems to me that @upsert can be set on the schema and it enforces uniqueness on a single predicate?

Follow up questions/examples

1.

If I set this
// user node
{
username: cameron
email: cam@gmail.com
}

Trying to set this would error, because it’s trying to create a new predicate with the same email, even though the node shape is different.

// alter ego node
{
alterEgo: evilCameron
email: cam@gmail.com
}

So I can never add another, cam@gmail.com email predicate, I could update it if I get hold of the node it’s attached to, or re-add it if I delete it (I guess). Is that right?

2.

Even if you have the @upsert directive set on multiple predicates, to perform an upsert on multiple predicates we still have to search for the node we want with all the predicate values relevant to the upsert, then update that node al in a transaction.

Or is there some type of multi predicate node linking @upsert?

Thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.