How to traverse through nodes with logic conditions on edge

Hi,
I’m looking to traverse through my nodes but attaching dynamic logic expressions on each of the edges.
EG: NodeA goes to NodeB only if x > 10, else to go NodeC
What is a performant way to implement this solution?

Thanks,
Ming

Would you mind sharing what you actually did? so I can look and make suggestions.

basically what i’ve done is like this

type Node {
    to: [Node] @hasInverse(field: from)
    from: [Node] @hasInverse(field: from)
 }

I’ve thought about something like this below, but it seems very unwieldy and turns the path into essentially a connection, and makes the graph unwieldy and messy for traversals and future scalability.

type Path {
    from: [ Node] @hasInverse(field: to)
    to: [Node] @hasInverse(field: from)
    logicFunction: String

Just wondering is there a better way. Facets looks interesting but I’m not sure if any custom logic can be added on to it.

Also am wondering if upcoming @custom logic could help with this.

thanks for the help
Ming

Oh, that was a GraphQL question (I have added the GraphQL tag). I don’t have totally familiarity with Dgraph’s GraphQL for now.
Maybe @pawan, @michaelcompton, or @vardhanapoorv would help.

Hi @mingsterism, thanks for the question.

I’m not sure I follow exactly what you are trying to do. Do you mean that when you are querying the graph you want to only have particular edges in the result if some conditions are meet? Or you want those conditions to hold as invariants of the data that you insert into your graph?

hey @michaelcompton
Do you mean that when you are querying the graph you want to only have particular edges in the result if some conditions are meet
Yes. i basiaclly want to traverse the graph in a specific direction based on some conditions. But these conditions are dynamically generated at runtime.

I was thinking is it possible to put dynamically generated properties on an edge. so the idea would be,

vertexA -> to vertexB (if x > 10)
             -> to VertexC (if x < 10)

x is dynamically generated at runtime.
was interested in @custom but not too sure if it’s possible.

Broadly, in Dgraph GraphQL±, you can do all sorts of interesting things using variables, math operators, aggregations etc. Those also let you effectively pull apart your graph search and put the result together in all sorts of ways. Check the docs from here onward if that interests you.

In GraphQL, you don’t have the same options built into the query language (largely as a consequence of how GraphQL works), but you will be able to do the kind of thing you are talking about using our new @custom directive. So, for example, you’ll be able to do something like

type VertexA {
  x: Int
  toVertexB: B @custom(...some function on x...)
  toVertexC: C @custom(...some other function on x...)

at the moment, those customs can only be calls to http functions (which could of course just make the corresponding graph query that you want), but we are also looking at allowing @custom to call directly back into same Dgraph so we can execute those kinds of calls without anything external being deployed. That sort of feature might help you here.

thanks so much for the clarification and guidance Michael.

allowing @custom to call directly back into same Dgraph

when do you see this being implemented?
also how shall we position our development with GraphQL and Graphql+. What will be the default start for future projects?
Will they be having features overlap? How do teams balance development using both query languages.

thanks,
Ming

Just touching base that there’s draft docs on custom logic now here https://graphql.dgraph.io/docs/, the beta version of the feature is in master and will be released in a beta release of 20.07.

We are also working on more guidance about how to use this feature, both in conjunction with other GraphQL± features and other tooling in the GraphQL ecosystem.