Have a filter based on the result from a subquery

Hi, I just want a way to do a filter based on the normalized result that I got from a subquery

{
   ID as q(func:has(Person))@normalize{
       _LinkedTo {
                 _LinkedTo {
                       ~_IsBy @filter(has(A))(orderasc:created,first:1) {
                           WT : created
                     }
                 }
               }
            ~_LinkedTo {
                 ~_IsFor @filter(has(A))(orderasc:created,first:1){
                      RT : created
                    }
               }  
         uid
     }
   p(func:uid(ID)) @filter((has(WT) AND NOT has(RT)) OR (gt(RT, WT))) {
           P : uid
	   expand(_all_)
     }

 
}

query q will return a result like this

"q": [
      {
        "uid": "0x7"
      },
      {
        "uid": "0x8"
      },
      {
        "RT": "2017-02-08T07:11:59Z",
        "WT": "2017-01-10T13:31:39Z",
        "uid": "0xa"
      },
      {
        "uid": "0x17"
      },
      {
        "uid": "0x1c"
      },
      {
        "uid": "0x22"
      },
      {
        "uid": "0x2d"
      },
      {
        "uid": "0x2e"
      },
      {
        "RT": "2015-10-14T20:42:26Z",
        "WT": "2016-06-09T12:33:58Z",
        "uid": "0x34"
      },
      {
        "RT": "2016-10-23T11:08:33Z",
        "uid": "0x35"
      },
      {
        "WT": "2016-09-01T11:25:21Z",
        "uid": "0x3e"
      }]

And what I want to do for query p is that based on q’s result, I want to find all the record that either only have WT or RT>WT.

WT and RT are in datetime format, as well as created.
and I got this error while running the query
: Got error: parsing time “writeTime” as “2006”: cannot parse “writeTime” as “2006” while running: name:“gt” args:"writeTime"

Wondering what would the query be like?

I’m trying to make a similar query:

Here I’d like to find all Classrooms that a user with a particular ID is in:

{
  classrooms(func: eq(type, "classroom")) @filter(has(~learns_in)) {
    title
    ~learns_in @filter(uid(0x1)) {
      name
    }
  }
}

While this does filter out all students except for 0x1, it also returns all of my classrooms that have any students at all. In Ratel it looks like this:

I can always make this query by starting with the User, and getting their classrooms – but i’m enjoying playing around with the query language to see what is possible.

Now after rereading this part. I noticed something. You want to somehow use a Normalized result. But I’m afraid that’s not possible. Normalize is a directive that works only on the block it used. There is no way to pass a “normalized” result to another block.

If not that, please reformularize your question.

Did you tried with uid_in ? Get started with Dgraph

In this part you do not need to use “has (~ learns_in)” in a Reverse way. Since it is a filter in Root, you can use it normally without “~” Since all Nodes linked by “@Reverse” have the same predicate do not need to do this.

You can simply search for the user, since you have his UID.


{ 
  user_with_a_particularID(func: uid(0x1))  {
    name
    learns_in  {
      title  #It will list all the classes he studies.
    }
  }
}

If you need to load all users and expand their study classes.


{ 
  user_with_a_particularID(func: has(_user)) @filter(has(learns_in)) {
    name
    learns_in  {
      title  #It will list all the classes their studies.
    }
  }
}

Thank you, this works exactly as I’d like:

{
  classrooms(func: eq(type, "classroom")) @filter(uid_in(~learns_in, 0x1)) {
    title
    learns_in
  }
}