Complex query

I’m creating a social networking platform, contains users categories and challenges as posts, each post has a relation with the user as author and category, for the user type it has relation with other users in (UID-list-reverse) followers Predicate same for the category,

What I want to do

I wanted to write a query that lists all challenges the user is following.

What I did

I've tried this query
{
  user(func: type(user)) { 
       x as uid
  following:~followers {
      uid
  } 
  challenge:  @filter(eq(author,val(x))){
      uid
      expand(_all_)
  }
  }
}

error:

while converting to subgraph: uid not allowed multiple times in same sub-query.

ps:
I know it doesn’t do what I want but worth the try

Dgraph schema

schema
<active>: bool @index(bool) .
<author>: uid @reverse .
<bDate>: datetime .
<bio>: string .
<cateId>: string @index(exact) .
<category>: uid @reverse .
<challenge>: uid @reverse .
<comments>: [uid] @count .
<content>: string @index(term) .
<createdAt>: datetime .
<description>: string @index(term) .
<downVotes>: [uid] @count @reverse .
<email>: string @index(exact) .
<fName>: string @index(term) .
<followers>: [uid] @count @reverse .
<isApproved>: bool @index(bool) .
<isChallenge>: uid @reverse .
<lName>: string @index(term) .
<lastSignIn>: datetime .
<multiMedia>: [uid] @count @reverse .
<name>: string @index(term) .
<password>: password .
<replayTo>: uid @reverse .
<uName>: string @index(exact) .
<upVotes>: [uid] @count @reverse .
type <category> {
	name
	description
	cateId
	createdAt
	isApproved
	followers
}
type <challenge> {
	author
	category
	content
	createdAt
	isChallenge
	multiMedia
	upVotes
	downVotes
	comments
}
type <comment> {
	author
	challenge
	content
	createdAt
	upVotes
	downVotes
	replayTo
	comments
}
type <user> {
	fName
	lName
	uName
	email
	bDate
	lastSignIn
	password
	bio
	active
	followers
}

This graph model is a bit confusing. Are you using followers to challenges and also friends? In your network, the user follows only “challenges”?

Can you tell what are the relations of you model?

e.g

user (in the edge followers) -> challenge -> to something?

I rewrote your query in a different way. But I haven’t done anything yet because I don’t quite understand your graph model.

{
  x as var(func: type(user))
  
  user(func: uid(x)) {
    following : <~followers> {
       uid
  } 
  challenge: "WHAT EDGE IS THIS? challenges?" @filter(uid(x))){
      expand(_all_)
  }
  }
}

Cheers.

i have 3 types user - category - challenge
user has followers type of user same for category, so the relation between user and user is followers, and category has a list of followers type user, challenge has relation with user with property author, and relation to category in the property category.
what I want is to query the uid of type user and it gives me the challenges related to all the followed categories and users.

So the traverse would be this?
user.followers -> category.followers -> challenge

I think you should use a better terminology. Instead of follow I would use assign or something. In general we use follow in relations between persons.

The Graph view from Ratel doesn’t help at all. What we would like to see is the structure of your dataset. The Graph view isn’t useful for these cases.

I modified the query based on what I understood so far.

{
  x as var(func: type(user))
  
  user(func: uid(x)) {
    following : <~followers> { #I don't understand why this is needed
       uid
  } 
  challenge: category @normalize {
      followers {
        name : name
      }
  }
  }
}

managed to do what I need with this query

{
  var(func: uid(0x2751)) {
    following: ~followers {
   
      challnges: @filter(has(~category) OR has(~author)) {
       a as   ~author
   b as ~category 
      }
    }
  }
    chall(func: uid(a,b)){
    dgraph.type
      author
      
    }
  }