Inner join like query

Hi,
Graph databases are no relational databases. Still, my mind take some time to adapt.

Given the schema:

type A {
  id ID
  b [B]
}

Type B {
  id ID
  somedata String
  c [C]
}

Type C {
  somefilter Boolean
  data String
}

How can I get those elements where A is choosen by id and C must match somefilter = true.

I know the GraphQL query would be like

query {queryA(filter: {id: 0x1}) {
  id
  b {
   id
   somedata
   c (filter: {somefilter: {eq: true}}) {
     id
     somedata
    }
  }
}}

but the problem is that elements get returned which satisfy the filter on A but may have no element B or element of type C. So the filters as a whole work like “outer joins”. Sure this can be fine but what if my filters in sum must match. Thus, what is the equivalent of an inner join?

btw. @cascade only helps in those cases, where all the requested fields should be set.#

Does GraphQL provide this expressiveness? If not, does DQL?

1 Like

Hi,

You should add the @cascade directive on b and it should work.
This directive eliminates result that doesn’t have the fields you want.

query {getA(id: "0x1") {
  id
  b @cascade{
   id
   somedata
   c (filter: {somefilter: {eq: true}}) {
     id
     somedata
    }
  }
}}
2 Likes