FormidableLabs / groqd

A schema-unaware, runtime and type-safe query builder for GROQ.
https://commerce.nearform.com/open-source/groqd
MIT License
221 stars 17 forks source link

groq-builder Make slice(0) nullable by default #268

Open heggemsnes opened 4 months ago

heggemsnes commented 4 months ago

Is there an existing issue for this?

Code of Conduct

Feature Request

Since we are not really reading validation on "min" for arrays, doing slice(0) should always infer to be nullable. 

Also with document queries, i.e:

`const pageQuery = q.star.filterByType("page").filter("slug.current == $slug").slice(0)`

groq will return null if the document doesn't exist. I feel like this should be the default. 

We can add .nullable() but I think it is more correct to make it default nullable in this scenario and perhaps add a .nonNullable() if necessary.
scottrippey commented 2 months ago

This is a great point. I like the idea of adding a .notNull() assertion too!