'How to filter any data on any filed is present or not in object in GraphQL

Below is my sample data which store in Dgraph

{
  "data": {
    "comp": [
      {
        "topologytemplate": {
          "namespace": "a",
          "nodetemplates": [
            {
              "name": "a",
             
            },
            {
              "name": "b",
            }
          ]
        }
      },
      {
        "topologytemplate": {
          "namespace": "c",
          "nodetemplates": [
            {
              "name": "a",
            },
            {
              "name": "b",
              "directives": [
                "a"
              ]
            },
          ]
        }
      }, 
    ]
  },
}

I want to filter data so that as a result we get data that does not contain "directives" filed. I am want to filter data using GraphQL query?

Currently, I am trying to filter data as follows:

query {
        comp(func: eq(dgraph.type,"QQQ")){
            name
       topologytemplate{
             nodetemplates @filter (eq(nodetypename,"a")){
               name
              directives
      }
    }
    }
}

Query to check that directives filed are present or not in nodetemplate?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source