Skip to content
Developerhome

Comparison

  Less than to read

Comparison operators are used to fetch specific objects based on greater or lesser than comparisons of a specific field.

In GraphQL, _gt (greater than), _gte (greater than or equal to), _lt (lesser than) and _lte (lesser than or equal to) are the comparison operators.

The following tables displays examples and results of applying filters with comparison operators. Some of the fields displayed are not mandatory and others have been omitted.

{
  xtremMasterData {
    item {
      query(filter: "{minimumPrice:{_gt:20}}") {
        edges {
          node {
            id
            name
            minimumPrice
          }
        }
      }
    }
  }
}
{
  "data": {
    "xtremMasterData": {
      "item": {
        "query": {
          "edges": [
            {
              "node": {
                "id": "TRAI010",
                "name": "Safety training",
                "minimumPrice": "800"
              }
            }
          ]
        }
      }
    }
  },
  "extensions": {
    "diagnoses": []
  }
}
{
  xtremMasterData {
    item {
      query(filter: "{_and:[{weight:{_gt:20}},{weight:{_lt:1000}}]}") {
        edges {
          node {
            id
            name
            weight
          }
        }
      }
    }
  }
}

{
  "data": {
    "xtremMasterData": {
      "item": {
        "query": {
          "edges": [
            {
              "node": {
                "id": "CMCOMPSN",
                "name": "CMCompSN",
                "weight": "150"
              }
            },
            {
              "node": {
                "id": "LSALOTSEQ",
                "name": "LSA-LOTSEQ",
                "weight": "250"
              }
            },
            {
              "node": {
                "id": "My Item ID",
                "name": "MyItemName",
                "weight": "100"
              }
            }
          ]
        }
      }
    }
  }
}

In the above example, the _and operator is mandatory because the two conditions - _gt and _lt - are applied to the same field.