What I want to do
Upsert data into Dgraph using Live Loader using the upsertPredicate option, against my GraphQL schema. I’m getting duplicate nodes despite having the xid set.
What I did
Here’s the Type definition:
type Country {
id: ID!
xid: String! @id @dgraph(pred: "xid")
country_code: String! @id @search(by: [exact])
country_name: String @search(by: [exact])
}
Here’s the sample .json file that I’m working with:
[
{"dgraph.type":"Country", "uid":"_:MEX", "xid":"MEX", "Country.country_code":"MEX", "Country.country_name":"Mexico"},
{"dgraph.type":"Country", "uid":"_:ARG", "xid":"ARG", "Country.country_code":"ARG", "Country.country_name":"Argentina"}
]
Here’s the command that I’m running:
dgraph live --files /data/1/data/dgraph/sample-data/json/countries1.json --alpha localhost:9080 --zero <zeroIP>:5080 --format json --cwd /data/1/data/dgraph --log_dir /data/1/logs/dgraph/ --upsertPredicate "xid"
If I run that twice, I’m expecting to see no new data inserted on the second run. Instead, I’m getting duplicate nodes:
curl --location --request POST 'http://localhost:8080/graphql' --header 'Content-Type: application/graphql' -d '
query MyQuery {
queryCountry {
id
xid
country_code
country_name
}
}
' | jq
{
"data": {
"queryCountry": [
{
"id": "0x41b556a",
"xid": "MEX",
"country_code": "MEX",
"country_name": "Mexico"
},
{
"id": "0x41b556b",
"xid": "ARG",
"country_code": "ARG",
"country_name": "Argentina"
},
{
"id": "0x44f36ac",
"xid": "ARG",
"country_code": "ARG",
"country_name": "Argentina"
},
{
"id": "0x44f36ad",
"xid": "MEX",
"country_code": "MEX",
"country_name": "Mexico"
}
]
} ......
What am I missing here? Thanks in advance for any guidance.
Dgraph metadata
dgraph version
Dgraph version : v21.03.1
Dgraph codename : rocket-1
Dgraph SHA-256 : a00b73d583a720aa787171e43b4cb4dbbf75b38e522f66c9943ab2f0263007fe
Commit SHA-1 : ea1cb5f35
Commit timestamp : 2021-06-17 20:38:11 +0530
Branch : HEAD
Go version : go1.16.2
jemalloc enabled : true