Query filter without invalid data

Hi, I would like get only nodes and edges between ‘pl’ cities and I get it but with the rest of pl cities that have no edge to other cities (because they’re from other countries).
My query looks like:

{ 
    f(func: has(ToCity))
    @filter(eq(country,"PL")) 
    {
    city     
    country
    ToCity @filter(eq(country,"PL"))
    {
      city
      country
    }
      Distance    
  }
}
JSON looks like this:
"data": {
    "f": [
      {
        "city_ascii": "Gdansk",
        "country": "Poland",
        "Distance": 7000
      },
      {
        "city_ascii": "Poznan",
        "country": "Poland",
        "Distance": 8654
      },
      {
        "city_ascii": "Torun",
        "country": "Poland",
        "Distance": 7037
      },
      {
        "city_ascii": "Lodz",
        "country": "Poland",
        "ToCity": {
          "city_ascii": "Poznan",
          "country": "Poland"
        },
(...)

I would like last data (with “ToCity”) edge only.
Thanks

Sorry, I don’t get it. You say “the rest of pl cities” which means “the rest of Poland cities” and you also say “because they’re from other countries”. I can’t understand this statement. There are Poland cities in other countries?

BTW, I recommend that you avoid using has at root. Do something like this:

f(func: eq(country,"PL")) @filter(has(ToCity))

Makes a huge difference in performance.

Odd, it should return nodes only with ToCity. Try this:

f(func: eq(country,"PL")) @filter(has(ToCity) AND Not has(~ToCity))

OR

f(func: eq(country,"PL")) @filter(has(ToCity) AND Not has(~ToCity)) @cascade
1 Like