Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why am I using the @ id instruction but it is invalid during execution #8915

Open
dht-hedaihua opened this issue Jul 23, 2023 · 1 comment
Open
Labels
kind/question Something requiring a response.

Comments

@dht-hedaihua
Copy link

dht-hedaihua commented Jul 23, 2023

Question.

What I want to do
I want to use the @ id command as expected in the official document

What I did
add the @id tag in the schema,like below:
mobile_number: String! @id @search(by: [hash, regexp])
successfully executed the import of the schema,and the ‘mobile_number’ field has tagged ‘upsert’ in rateUI web.

I successfully added a node with ‘mobile_number’ attribute value. Then I tried to add another node with the same ‘mobile_number’ value as the previously added node. My expectation is that the dgraph should have reported an error, causing the addition to fail because I have already added the @ id tag to the ‘mobile_number’ field. However, it was successfully added. Now there are two nodes of the same type with the same ‘mobile_number’ value successfully in the library.

May I ask why this is? Is there something wrong with my operation or configuration? Thank you to any friend who can help me. Thank you!

Dgraph metadata
docker run dgraph/standalone and rateUI , the version is v23.0.0
the result json content is :

{
  "data": {
    "user_general_info": [
      {
        "uid": "0x4e23",
        "User.mobile_number": "XXXXXXXXX",
        "User.user_full_name": "hedaihua",
        "User.gender": "",
        "User.birthday": "0001-01-01T00:00:00Z",
        "User.updated_at": "0001-01-01T00:00:00Z",
        "User.created_at": "2023-07-16T09:00:31.0370496Z"
      },
      {
        "uid": "0x4e24",
        "User.mobile_number": "XXXXXXXXX",
        "User.user_full_name": "hedaihua",
        "User.gender": "",
        "User.birthday": "0001-01-01T00:00:00Z",
        "User.updated_at": "0001-01-01T00:00:00Z",
        "User.created_at": "2023-07-16T09:04:13.7249037Z"
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 141903,
      "processing_ns": 886312,
      "encoding_ns": 69300,
      "assign_timestamp_ns": 1234717,
      "total_ns": 2441835
    },
    "txn": {
      "start_ts": 20127
    },
    "metrics": {
      "num_uids": {
        "User.birthday": 2,
        "User.created_at": 2,
        "User.gender": 2,
        "User.mobile_number": 2,
        "User.updated_at": 2,
        "User.user_full_name": 2,
        "User.user_type": 2,
        "_total": 16,
        "uid": 2
      }
    }
  }
}

I have used mutation addition in RateUI web and also added it using the official go client sdk. The results were all successfully added as described above. The key code added to used by go client sdk is as follows:

 // do create
	mu := &api.Mutation{
		CommitNow: true,
	}
	pb, err := json.Marshal(ugi)
	//error handle
	mu.SetJson = pb
	res, err := d.dTxn.Mutate(ctx, mu)
	//error handle
@dht-hedaihua dht-hedaihua added the kind/question Something requiring a response. label Jul 23, 2023
@harshil-goel
Copy link
Contributor

You have added a GraphQL schema. That's where we support @id feature. However the mutation you are doing is using DQL. It's a different language that we support to query data. This language doesn't support @id yet. You will need to do GraphQL mutations if you want to use the @id feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Something requiring a response.
Development

No branches or pull requests

2 participants