Hi, I am at the v early stages of designing an event store for an ecommerce site, and wish to model as a graph. I’m not sure whether events should be nodes or edges, but my first iteration is to model as edges. Had some success with some basic use cases, but one interesting question I’m stumbling on is, what products our customers have added to cart but where not purchased.
I’m getting a bit stuck and would really appreciate some tips.
This is my initial graph:
I want a query to return:
Danielle <add_to_cart> shag rug
Joe <add_to_cart> $10 gift card
You can run the above query for all the customers or a better and efficient approach would be to fetch the products purchased as well as added by each customer and post-process the two sets (purchased and added) to find the set difference in the client side. I am trying to think of a single query which can do this.
Awesome!! Thanks @ahsan
I did have a similar half cooked var approach. (One thing I was mulling over when writing my var approach, was how such a query gets executed, e.g. is it 2 queries, one to get the var and the second to apply, and if its a good approach when parsing a lot of data, etc).
But a single query to run for all nodes would be fantastic, and to see how it can be done would really help me!
An another approach that would enable us to do this in a single query would be to use facets. We can have an edge called “interacted” with facets (purchased=False, add_to_cart=True). So a sample mutation would look like:
Thanks @ahsan, i dont think that will be extensible enough for what we need to achieve. We will have a lot of events and that will be hard to maintain in a facet. Plus for each event, i will prob need to capture a create date and other meta data about the event.
Yes right. It will become cumbersome after a point. we have an RFC to include loops in the query; Add foreach() function, which will probably make querying for each customers straight-forward.
I think you are good with the first iteration of your model, and you could probably go with the first solution or with the facets solution. We hope to get loops within query that would help us do this without facets.
Other than this, feel free to raise questions as you go ahead.
Ok, thanks @ahsan, the facets is not a runner really, so looks like this would need to done in an app. Hopefully loops within query will arrive soon… Thanks again for your help