Download tutorial as e-book ⚡️

Where Clause

So now we've set up a basic data connector for a SQLite database running locally. Now we'll start to implement predicates by turning them into where clauses in the generated SQL.

Predicates in GraphQL are expressions which determine the conditions under which data is retrieved or manipulated. For example: a where clause.

Where Clause

Let's pick up from where we left off. We can modify our SQL template in our fetch_rows function to now include a WHERE clause:

const sql = `SELECT ${fields.join(", ")} FROM ${request.collection} ${where_clause} ${limit_clause} ${offset_clause}`;

To generate our WHERE clause, we will need to interpret the contents of the where property of the query request. To see what this will look like, we can find some examples in the snapshots we generated last time:

"Limit": 10,
"where": {
"type": "binary_comparison_operator",
"column": {
"type": "column",
"name": "artist_id",
"path": []
"operator": {
"type": "equal"
"value": {
"type": "scalar",
"value": 5

This predicate expression has type binary_comparison_operator, which means it is a predicate which compares a column to a value using an operator, in this case, the equality operator - this predicate asserts that the artist_id column equals the literal value 5.

Let's look at other expression types in the next section.

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved