Hello. I read the graphql doc and find there isn't exist mutation of upsert(or createOrUpdate) which is very useful in batch update, it has been implemented by Dgraph. https://dgraph.io/docs/graphql/mutations/upsert/
I only find connectOrCreate which can create or connect the node, but don't offer hook to UPDATE the property's value of match(connect) node.
Say we have a schema
type Product {
id: ID @id
name: String
hsCode: String
price: Currenty @relationship(type: "HAS_PRICE", direction: OUT)
}
type Currenty {
id: ID @id
currencyCode: CurrencyCode @default(value: USD)
amount: Float!
}
enum CurrencyCode {
"US Dollar"
USD
"EURO Currency "
EUR
"Japan Yuan"
JPY
"Hongkong Dollar"
HKD
"China Yuan"
CNY #ISO 4217
}
I want to update the name of Product and amount of price within same mutation. Sometime we will offer price when create product, but something not.
So when I want to update price of product, there maybe has not price(type: Currency).
What I expected is when the price is not exsisted(determined by id), it will created a new one, if the price's id exist, it will update the node with the given data within some method such as onUpdate or onCreateOrUpdate...
mutation xx{
updateProducts(
where:{id:"***"}
update:{
name: "Foobar"
price:{
connectOrCreate:{ // I want another upsert operation here
where:{id:"**"}
onCreate // It should have onConnect hook too. So we can update the node here, such as onConnect { node: { name: "Product A" } }, we will match the node and UPDATED at the same time here.
// if will have onCreateOrUpdate hook here, it will be great, I will update or create from given data without considering which type(create or connect) of mutation it take.
}
}
}
)
}
So I was stuck now, I can't update the price if the id exist. I have to write another Mutation to do this task. So I have two Mutation for nested update, also I have to judge if the price's id(type Currency) is exisit before I decide which Mutation to apply.
... View more