groqd icon indicating copy to clipboard operation
groqd copied to clipboard

groq-builder Make slice(0) nullable by default

Open heggemsnes opened this issue 1 year ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Code of Conduct

  • [X] I agree to follow this project's 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.

heggemsnes avatar Feb 17 '24 16:02 heggemsnes

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

scottrippey avatar May 01 '24 18:05 scottrippey