Does GraphQL support substringof?

This query works to find an entry based on exact match:

{
  queryRecipesContents(filter: "data/title/iv eq 'Mexican Black Bean Soup'") {
    data {
      title {
        iv
      }
    }
  }
}

This returns:

{
    "data": {
        "queryRecipesContents": [
            {
                "data": {
                    "title": {
                        "iv": "Mexican Black Bean Soup"
                    }
                }
            }
        ]
    }
}

Would it be possible to do a search based on a partial match with a string? Such as this:

{
  queryRecipesContents(filter: "substringof('Mexican', data/title/iv) eq true") {
    data {
      title {
        iv
      }
    }
  }
}

This returns the error:

{
  "data": {
    "queryRecipesContents": null
  },
  "errors": [
    {
      "message": "OData $filter clause not valid: ex.Message.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

You can use something like

$filter=contains(data/title/iv, 'Mexican')
1 Like

This is perfect! Thank you :slight_smile:

For anyone looking to implement a similar query, the GraphQL looks like:

{
  queryRecipesContents(filter: "contains(data/title/iv, 'Mexican')") {
    data {
      title {
        iv
      }
    }
  }
}
1 Like