How to use DQL to query those film's name of (starring is _:luke and starring is _:leia)?

how to use DQL to query those film’s name of (starring is _:luke and starring is _:leia)?
schema is:

<dgraph.graphql.schema>: string .
<director>: [uid] .
<name>: string @index(fulltext, term) .
<release_date>: default .
<revenue>: default .
<running_time>: default .
<starring>: [uid] @reverse .
type <dgraph.graphql> {
	dgraph.graphql.schema
}

dataset is :

{
  set {
   _:luke <name> "Luke Skywalker" .
   _:luke <dgraph.type> "Person" .
   _:leia <name> "Princess Leia" .
   _:leia <dgraph.type> "Person" .
   _:han <name> "Han Solo" .
   _:han <dgraph.type> "Person" .
   _:lucas <name> "George Lucas" .
   _:lucas <dgraph.type> "Person" .
   _:irvin <name> "Irvin Kernshner" .
   _:irvin <dgraph.type> "Person" .
   _:richard <name> "Richard Marquand" .
   _:richard <dgraph.type> "Person" .

   _:sw1 <name> "A New Hope" .
   _:sw1 <release_date> "1977-05-25" .
   _:sw1 <revenue> "775000000" .
   _:sw1 <running_time> "121" .
   _:sw1 <starring> _:luke .
   _:sw1 <starring> _:leia .
   _:sw1 <starring> _:han .
   _:sw1 <director> _:lucas .
   _:sw1 <dgraph.type> "Film" .

   _:sw2 <name> "The Empire Strikes Back" .
   _:sw2 <release_date> "1980-05-21" .
   _:sw2 <revenue> "534000000" .
   _:sw2 <running_time> "124" .
   _:sw2 <starring> _:luke .
   _:sw2 <starring> _:han .
   _:sw2 <director> _:irvin .
   _:sw2 <dgraph.type> "Film" .

   _:sw3 <name> "Return of the Jedi" .
   _:sw3 <release_date> "1983-05-25" .
   _:sw3 <revenue> "572000000" .
   _:sw3 <running_time> "131" .
   _:sw3 <starring> _:luke .
   _:sw3 <starring> _:leia .
   _:sw3 <director> _:richard .
   _:sw3 <dgraph.type> "Film" .

   _:st1 <name> "Star Trek: The Motion Picture" .
   _:st1 <release_date> "1979-12-07" .
   _:st1 <revenue> "139000000" .
   _:st1 <running_time> "132" .
   _:st1 <dgraph.type> "Film" .
  }
}

Your dataset is broken. I have tried to fix it, but I can’t cuz I don’t know all the missing preds.

Hi @cangchen8180, welcome to the forum.

Michel is right. Your dataset seems to have some formatting mistakes; it’s missing some predicates in some fields. Compare your dataset to the dataset here. For example your last set of fields should be:

_:st1 <name> "Star Trek: The Motion Picture" .
_:st1 <release_date> "1979-12-07" .
_:st1 <revenue> "139000000" .
_:st1 <running_time> "132" .
_:st1 <dgraph.type> "Film" .

You’re missing the <name> and <revenue> predicates.
You have similar missing pieces in previous sets. Fix those and you won’t have trouble running the mutation and then perform queries.
Hope this helps.

@sakib My mistake . Then i updated this dataset. thank you very much.

But My trouble is I dont know how to query to get those films which has multiple starrings simultaneously.
For example: those films which include two persons (Luke and Leia) simultaneously.

my now dql is this, but this dql is complex and slow.
@MichelDiz @sakib do you have better dql to get the data?
now is

{
  var(func:eq(name, "Luke Skywalker")) @cascade{
    A as ~starring{}
  }
  B as var(func:uid(A)) @cascade{
   starring @filter(eq(name, "Princess Leia")){}
  }
  films(func: uid(B)) {
    uid
    name
    starring{
      uid
    	name
    }
  }
}

result is

Slow how? This query looks pretty okay to me. Can be something on your side.

You don’t need cascade here. And the curly braces e.g

  var(func:eq(name, "Luke Skywalker")) {
    A as ~starring
  }

In the first block you are collecting all Luke’s movies and in that second one you are applying the filter with Leia. Looks normal to me.

BTW, I would do like

{
  Luke as var(func:eq(name, "Luke Skywalker")) {
    A as ~starring
  }
  var(func:uid(A)) @cascade {
   B as uid
   Leia as starring @filter(eq(name, "Princess Leia"))
  }
  films(func: uid(B)) {
    uid
    name
    starring @filter(uid(Luke,Leia)) {
      uid
      name
    }
  }
}

About the second block - I think there is a difference when using cascade. I don’t remember well. If not so, nevermind.

About the films block, filter the starring with the target seems logic as you wanna check both Luke and Leia relation.

the result of your query is incorrect for me.

the result of your query :

i want this result:

Assuming this, I think Han Solo shouldn’t be in the result. Even if he is in the movie.

Yeah, cuz when I mentioned “About the second block - I think there is a difference when using cascade. I don’t remember well. If not so, nevermind.” I wasn’t sure in which way it would fail. So fixing it bellow.

{
  Luke as var(func:eq(name, "Luke Skywalker")) {
    A as ~starring
  }
  B as var(func:uid(A)) @cascade {
   Leia as starring @filter(eq(name, "Princess Leia"))
  }
  films(func: uid(B)) {
    uid
    name
    starring @filter(uid(Luke,Leia)) 
      {
      uid
      name
    }
  }
}

Result

{
  "data": {
    "films": [
      {
        "uid": "0x272f",
        "name": "Return of the Jedi",
        "starring": [
          {
            "uid": "0x272b",
            "name": "Princess Leia"
          },
          {
            "uid": "0x2731",
            "name": "Luke Skywalker"
          }
        ]
      },
      {
        "uid": "0x2734",
        "name": "A New Hope",
        "starring": [
          {
            "uid": "0x272b",
            "name": "Princess Leia"
          },
          {
            "uid": "0x2731",
            "name": "Luke Skywalker"
          }
        ]
      }
    ]
  }

I get it. thanks.