type Foo {
bars: [Bar!]!
}
type Bar {
name: String!
}
I want to get all Foos that have a Bar with name == “Alice” and a Bar with name == “Bob”.
I don’t want to get incompleteFoos, i.e. entities that only have a bar with one of these names.
I also don’t want to add another field to Foo
Preferable this should be done using GraphQL, but DQL would also be possible.
{
var(func: has(Foo.bars){
B as Foo.bars
}
q(func: uid(B)) @filter(eq(Bar.name, "Alice")) {
Bar.name
}
}
In GraphQL is another Story. I would have to get my head in sync with GraphQL to be able to help you. As GraphQL doesn’t have multi-blocks and variables. I think this strategy is quite different.
{
q(func: has(Foo.bars)) @filter(uid_in(Foo.bars, uid(A)) AND uid_in(Foo.bars, uid(B))) {
Foo.id
}
A as var(func: eq(Bar.name, "Alice"))
B as var(func: eq(Bar.name, "Bob"))
}