I’m currently attempting to use dgraph to store data that is webscraped with Node.js
My schema currently looks like this:
type GraphicsCardPriceDatum {
date: DateTime!
price: Float!
}
type GraphicsCard {
passmarkId: String! @id
cardName: String! @search(by: [term])
lookupUrl: String!
lastUpdated: DateTime! @search
firstUpdated: DateTime @search
priceHistory: [GraphicsCardPriceDatum]
g3d: Int
g2d: Int
samples: Int
busInterface: String
maxMemory: String
coreClock: String
memoryClock: String
directX: String
openGL: String
maxTdp: String
powerPerf: String
category: String @search(by: [hash])
rank: Int
}
The webscraper runs every week, generating a JSON array, one object per graphics card. I would like to perform an upsert that either creates a new node for each datum, or updates an existing node if its passmarkId matches. Note that passmarkIds CANNOT be dgraph’s internal UIDs. The update logic is to simply replace all values for a particular card with available new values, save for priceHistory.
For priceHistory, if the node already exists, its existing priceHistory list should be concatenated with a new price + date datum, and updated. If the node is new, a single-item list with the just-scraped price + date datum should be created.
I’m sure my newness to graph DBs and dgraph is showing here, but it isn’t immediately obvious to me how to do this in a constant number of requests.
I’ve attempted to do this with a GraphQL query and then an add + update mutation, but I couldn’t quite figure out how to do a bulk update. I’ve also attempted to figure out how to do this using the upsert block, but I can’t figure out how to inject my custom update logic between the query and mutation step.
Hate asking other people to write code for me in a question, but could someone advise on how to do this? Thanks.