Query with @filter on a list/non-scalar objects at root level

Hope everyone does not mind about this naive question. I’m learning GraphDB/Dgraph and followed the “Getting start” https://dgraph.io/docs/get-started to successful setup a local playground.

I’m able to query data using filter and connecting filters on scalar fields, but failed when trying to filter based on existing of list element.

With this query:

{
  data(func: type(Film)) @recurse(loop:false) 
  @filter(eq(director,"George Lucas"))
  {
    uid
    expand(_all_) 
  }
}

I get the following error:

{
  "name": "t",
  "url": "http://localhost:8080/query?timeout=20s",
  "errors": [
    {
      "message": ": Got error: Attribute director is not valid scalar type while running: name:\"eq\" args:\"George Lucas\" ",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

Can someone please help to correct the filter? I’ve tried with @filter(eq(director.name,“George Lucas”)) but got empty data return. I guess director.name is seen as a scalar and not how to indicate the field of the element in the list to search for.

Thank you.

By having the @filter of director at predicate level, I can filter the response to only selected director. However it wont allow the recurse directive and expand(all) which I would like to have, so all detail data are provided. Any suggestion beside I need to list all the fields in the query?

{
  data(func: type(Film)) 
  @filter(has(director))
  {
    director @filter(eq(name,"George Lucas")) {
       expand(_all_) 
    }
  }
}

Response:

{
  "data": {
    "data": [
      {
        "director": [
          {
            "name": "George Lucas"
          }
        ]
      }
    ]
  },
...
}

Thank you.

@binhle can you edit these and format the code wrapping them in code blocks beginning with three backticks and ending the same. It will really help readability.Preformatted.

Thanks @amaster507 - I can’t find the option to edit the published posts, so I will keep in mind about formatting the quoted code from now on.

I went through the example you quoted, the concept is similar to what I had in my second post on the topic, in which the filter will be applied at predicate level.

What I am trying to get is how we can apply the filter at the root level, so that I can make use of @recurse() at the root and expand(all) in the body so it will dynamically traverse through all nested data.