mrjbj
mrjbj

Reputation: 379

How can I query Hasura API over HTTP to invoke SQL "WHERE LIKE" behavior?

I'm trying to update the ra-data-hasura library to allow filtering based upon partial matches. I've discovered how to call the server over HTTP via the PostMan tool, but cannot find a way to get the "where" property to look for partial (as opposed to exact) matches (see image below). Is there a way to this (e.g. call for something like "WHERE description LIKE 'Milestone%'")?

Image showing PostMan call to Hasura

Upvotes: 0

Views: 222

Answers (1)

Johan Eliasson
Johan Eliasson

Reputation: 222

Either use GraphQL:

http://example.com/v1/graphql

{
  lifeplan_planning_type(
    limit: 10,
    offset: 0,
    where: {description: {_like: "Milestone%"}}
  ) {
    id
    description
  }
}

or a regular SQL:

http://example.com/v1/query
{
    "type": "run_sql",
    "args": {
        "sql": "SELECT * FROM lifeplan.planning_type WHERE description LIKE "Milestone%" LIMIT 10 OFFSET 0 ORDER BY id ASC"
    }
}

More info in Hasura's documentation:

https://hasura.io/docs/1.0/graphql/manual/api-reference/schema-metadata-api/run-sql.html#run-sql

Upvotes: 1

Related Questions