Home / Companies / Nhost / Blog / Post Details
Content Deep Dive

Write Better GraphQL "where" Queries with Hasura

Blog post from Nhost

Post Details
Company
Date Published
Author
Johan Eliasson
Word Count
295
Language
English
Hacker News Points
-
Summary

Hasura developers often make the mistake of writing inflexible GraphQL where-queries by hardcoding specific conditions, such as filtering people by age and name patterns, which limits the query's reusability. An example of this is a query that specifies age and nameLike as variables, which requires new queries for different filters. To enhance flexibility and reusability, it's recommended to write more generic queries using a people_bool_exp variable for where expressions, allowing developers to modify the query conditions dynamically by adjusting the GraphQL variable. This approach enables the same query to be used for various filtering requirements without rewriting the query.