Inject uid into child

Hi there,

I’m trying to include the uid of a parent as a field on the children within my query. I’ve been trying to use variables, but I haven’t been able to get it to work. Here’s a sample of the query I’m trying to perform:

q(func: uid(${problem.uid})) {
  problemID as uid
  solution {
    uid
    text
    problemID : val(problemID)
  }
}

The following query should do it.

a as var(func: uid(${problem.uid})) {
}

q(func: uid(a)) {
uid
solution {
uid
text
problemId: uid(a)
}
}

Thanks for the quick reply!

I’m getting an error Cannot do uid() of a variable

Here’s my exact query:

    {
      a as var(func: uid(0x27d0)) {}

      q(func: uid(a)) {
        solutions : solution @facets(orderasc: sortOrder, sortOrder: sortOrder) {
          uid
          expand(_all_)
          parentID: uid(a)
        }
      }
    }

Hey @smkhalsa

Variables won’t do it in this case. One way that I can think of is having a reverse edge on solution, then you could do

solution: uid @reverse .
q(func: uid(${problem.uid})) {
  problemID as uid
  solution {
    uid
    text
    ~solution {
      uid
    }
  }
}

Though I think we could allow fetch uid variables and then the query @janardhan supported should work. Can you please file an issue so that we can look into supporting it?

Ok, I created an issue for this. Thanks for the suggestion. I already have a reverse edge, so that should work fine for now.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.