Skip to content

More information in response for Upsert #4048

@MichelDiz

Description

@MichelDiz

Experience Report

What you wanted to do

I would like to execute Upserts transactions and have a logical response from what is happening. Sometimes we send a transaction that does not return contextual information about the transaction itself. We only have some information when the transaction creates a new object in the DB. But it's not human-friendly.

Why that wasn't great, with examples

For example, if I want to bind two entities in one Upsert. I will get a "Success" + "Done" code and an empty "uids" field. This information does not help me debug what is happening. I know there was writing because I can check directly by making a new query.

{
  data: { code: 'Success', message: 'Done', uids: {} },
  extensions: {
    server_latency: { parsing_ns: 73769, processing_ns: 5960909 },
    txn: { start_ts: 653, commit_ts: 654 }
  }
}

What we need is something like (That would be just a sketching idea, certainly should follow established standards/patterns):

If the user sends an upsert and there was a writing in Dgraph.

{
  data: { code: 'Success', recorded: 'true', message: 'Done', uids: { 'uid(USER)': '0x5092d' } }
 //(...)
}

If the user sends an upsert and there was no writing in Dgraph.

{
  data: { code: 'Success', recorded: 'false', message: 'Done', uids: {} }
 //(...)
}

Now let's say I use "cond()" on a mutation. I have no information about the context of this condition when performed. Whether it wrote it or not. Let's say my cond is "@if (NOT eq (len (USER), 1))" - ie it will only write if the value is zero. This happens without the dev/user being aware of what is happening.

In the Cond hypothesis, it would be ideal to return values ​​confirming or not the writing.

If the user sends an upsert with a condition (@if(NOT eq(len(USER), 1))) and there was a writing in Dgraph.

In this case, we assume that the result of the condition was "found no user". Since the condition proposal matches the result then the answer is "cond: 'true'".

{
  data: { code: 'Success', recorded: 'true', message: 'Done', uids: { 'uid(USER)': '0x5092d' }, cond: 'true' }
 //(...)
}

In the case of multiple conditions (as it would be in the case of multiple mutations), then each new condition would have to have a field of its own. e.g. cond0: 'true', cond1: 'false', cond2: 'true',

Maybe

cond: {0: 'true', 1: 'false', 2: 'true'},

named mutations

cond: { "userMutation": 'true', "schoolEnroll": 'false', "inSelection": 'true'},

Metadata

Metadata

Assignees

Labels

area/upsertIssues related to upsert operations.kind/enhancementSomething could be better.priority/P2Somehow important but would not block a release.status/needs-specsIssues that require further specification before implementation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions