I'm trying to run a query on a graph of people that, for a given user, returns all vertices that are a friend of friend of that user AND that have the same last name. I'm having trouble storing an accessing property values from earlier in the traversal in a way that works with the given functions. I've tried:

let query = g.V(userId)
      .sideEffect(
        __.values("lastName")
          .as("userLastName")
      )
      .out("isFriendsWith")
      .out("isFriendsWith")
      .where(
        __.has("lastName", __.select("userLastName"))
      )
      .where(
        __.not(
          __.in_("isFriendsWith").hasId(userId)
        )
      )

g.V(userId)
      .as("user")
      .out("isFriendsWith")
      .out("isFriendsWith")
      .where(
        __.has("lastName", __.select("user").values("lastName"))
      )
      .where(
        __.not(
          __.in_("isFriendsWith").hasId(userId)
        )
      )
    g.V(userId)
      .as("user")
      .out("isFriendsWith")
      .out("isFriendsWith")
      .where(
        __.values('lastName').is(__.select("user").values("lastName"))
      )
      .where(
        __.not(
          __.in_("isFriendsWith").hasId(userId)
        )
      )

Here's a query to start up a small sample data set. We should return Billy, but not John, Sarah, or Sally.

await g.addV("user").property("firstName", "John").property("lastName", "Doe")
      .as('john')
      .addV("user").property("firstName", "Sally").property("lastName", "Doe")
      .as('sally')
      .addV("user").property("firstName", "Billy").property("lastName", "Doe")
      .as('billy')
      .addV("user").property("firstName", "Sarah").property("lastName", "Johnson")
      .as('sarah')
      .addE("isFriendsWith")
      .from_(__.select('john'))
      .to(__.select('sally'))
      .addE("isFriendsWith")
      .from_(__.select('sally'))
      .to(__.select('billy'))
      .addE("isFriendsWith")
      .from_(__.select('sally'))
      .to(__.select('sarah'))

They don't throw errors, but they either filter too heavily (nothing in the list) or too lightly (where is always true). I have double checked that there are valid target nodes in the graph, so the query should be returning something. When I hardcode the lastName instead of trying to access it from the origin node, it works.

I've broadly been frustrating with understanding how gremlin types work in gremlin js since the documentation is so sparse. Not sure how well translating between the java docs works.

0

There are 0 best solutions below