Dhananjay Gahiwade
Dhananjay Gahiwade

Reputation: 359

How to filter data with nested object in GraphQL

query {
    comp(func: eq(dgraph.type,"ServiceTemplate")) {
    topologytemplate{
        nodetemplates { 
             name
             namespace @filter (eq(url,"a_url")){
                    url
            }
         }
      }   
   }
}

Using the above query I am want to filter data that nodetemplate objects have matching URL that we are passing in query and we get a list of all nodetemplates but I am getting result as follows:

{
  "data": {
    "comp": [
      {
        "topologytemplate": {
          "nodetemplates": [
            {
              "name": "a",
              "namespace": {
                "url": "a_url"
              }
            },
            {
              "name": "b"
            },
            {
              "name": "c"
            },
            {
              "name": "d"
            },
            {
              "name": "e"
            },
            {
              "name": "f",
              "namespace": {
                "url": "b_url"
              }
            },
            {
              "name": "g"
            }
          ]
        }
      }
    ]
  },
}

But I want only those nodetemplates that have URLs that we are going to filter using graphQL. Any idea how to filter it.

Upvotes: 5

Views: 384

Answers (1)

Michel Conrado Diz
Michel Conrado Diz

Reputation: 321

This is DQL, not GraphQL.

You could use the directive "@cascade"

{
    comp(func: eq(dgraph.type,"ServiceTemplate")) @cascade {
    topologytemplate{
        nodetemplates { 
             name
             namespace @filter (eq(url,"a_url")){
                    url
            }
         }
      }   
   }
}

Upvotes: 0

Related Questions