Works_for, how does it work?

following the tutorial here:

https://tour.dgraph.io/schema/2/

how do i query for all users for any company?

how do i query for all that works with respective company1 or company2?
how do i query for all bosses of respective company1 OR company2?

how do i query for all those works for industry “High Tech”?

if i add a employee with name, age and start_at, and set this employee to work for company1, how do change that query to do this?
can i add a query to append works_for in subsequence mutation?

thank you

Try:

{
All_users(func: has(name), first: 10000) @filter(NOT has(industry)){
    uid
   expand(_all_)
  }
}

more about has: https://docs.dgraph.io/query-language/#has

{
All_users(func: has(works_for), first: 10000) {
    uid
   expand(_all_)
  }
}
{
All_users(func: has(boss_of), first: 10000) {
    uid
   expand(_all_)
  }
}
{
All_users(func: has(industry)) @filter(eq(industry, "High Tech")) {
    uid
   expand(_all_) {expand(_all_)}
  }
}

OR

{
All_users(func: has(industry)) @filter(eq(industry, "High Tech")) {
    uid
   ~works_for { 
            uid
            name
            boss_of {expand(_all_)}
   }
  }
}
{
All_users(func: has(name), first: 10000) @filter(NOT has(industry)){
    uid
    name
    age
    start_at
  }
}

OR

{
All_users(func: has(industry), first: 10000) {
 ~works_for {
    uid
    name
    age
    start_at
   }
  }
}

Nops. The language you use should have a way for you to assign the industry UID to a variable to then use on a mutation. Mutation and Query can not run together, they are separate operations.

Cheers.

awesome thank you @MichelDiz
I will digest it :slight_smile:

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