Upsert request returning null with no explanations

Hi everyone, i’m using dgraph to build a dashboard.
I’m trying to import various domain alerts with an upsert.

The idea is to have unique DomainAlert using a unique combined key (domain + week)

after the first insertion, i can’t enter anymore DomainAlert. i get no errors, just

{
  "addDomainAlert": null
}

Please find the schema and the request tested below. If anyone can help me

------- gql  schema ---------
type DomainAlert {
    domain: String!  @search(by: [exact]) @id
    week: Int! @id
    date: DateTime!
    rate: Int
    domainExpiration: DateTime
    domainExpirationWeek: Int
    sslExpiration: DateTime
    sslExpirationWeek: Int
    alerts: [Alert] @hasInverse(field: "domain")
}

type Alert {
    domain: DomainAlert!
    source: String
    url: String
    title: String!
    description: String
    status: String @search
}
------- gql  schema ---------

simple upsert does nothing

mutation addDomainAlert {
  addDomainAlert(input: {domain: "www.oferhitech.com", date: "14-07-2021", week: 28}) {
    domainAlert {
      domain
    }
  }
}

return

{
  "addDomainAlert": null
}

or upsert with variables
query:

mutation UpsertDomainAlert($input: [AddDomainAlertInput!]!) {
 addDomainAlert(input: $input, upsert: true) {
    numUids
     }
  }

variables:

{
  "input": {
    "rate": 0,
    "domain": "www.oferhitech.com",
    "date": "2021-07-14T17:27:15.757311+02:00",
    "week": 28,
    "domainExpiration": "0001-01-01T00:00:00Z",
    "domainExpirationWeek": 0,
    "sslExpiration": "2021-11-13T00:00:00Z",
    "sslExpirationWeek": 45
  }
}

return

{
  "addDomainAlert": null
}

There is no concept of multifield unique key at the moment in Dgraph. The @id only keeps the values unique for that single field. So you cannot have more than one node with the same week even if the domain is different, and you cannot have more than one node with the same domain even if the week is different. If this is what you need, then you will have to add that logical key as a new field domainWeek: String @id and then manually concatenate the values and add them into that field when inserting data.

1 Like

thanks