Joint session with Vercel: How to build intelligent storefronts (May 15th)

Handle Certain Values To Be True

If you want to pass a parameter to a query that might not always be defined

By James Singleton & Geoff Ball


Query

*[_type == 'post' && select(
  $id == null => true,
  _id == $id
)]

I ran into an issue where sometimes I would be passing a parameter into a groq query that wasn't defined. For example, if you had a query param ?category=foo to help narrow down a search result. If you wanted to go back to seeing all of that search result, it would be nice (in my opinion) to not have to call a completely separate query.

Contributors

James Singleton

Senior Software Engineer at AmEx

Visit James Singleton's profile

Geoff Ball

Support Engineer at Sanity.io

Canada

Visit Geoff Ball's profile