You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been using groqd for a while, and while implementing Sanity's preview mode, I realized most (if not all) fields end up being null in draft state (except for the slug). I think it would be pretty useful to have a way where everything is nullable by default. I understand the typescript could get kind of tricky with this but do you think either having a way to do this with declaration merging (not sure if it's possible) or maybe something similar to grab$ but with a different symbol would be useful?
The text was updated successfully, but these errors were encountered:
Have been trying to think through what this might look like.
Currently thinking maybe something like a .draft() method on a query might be nice for this. Would add some TS considerations while applied tho.
Here's the basic idea I'm tossing around:
import{q,typeDraft,typeSelection,typeTypeFromSelection}from'groqd'constpokemonSelection={name: q.string(),attack: ["base.Attack",q.number()],}satisfiesSelectiontypeSanityPokemon=TypeFromSelection<typeofpokemonSelection>// ^? { name: string; attack: number }// Added Draft<T> utility type if you're using selections to define component prop typestypeSanityPokemonDraft=Draft<SanityPokemon>// ^? { name: string | null | undefined; attack: number | null | undefined }constquery=q("*").filterByType("pokemon").grab(pokemonSelection)// Added draft method which would go through all properties in the schema and make them nullish.// Would also be compatible following .grabOne() or .select().draft()
Only annoying thing is it would impact all type definitions down stream of the query and you'd have to account for nullish scenarios that might not be applicable once you remove the .draft() method.
I'm wondering if there's a more elegant approach 🤔 ... but in general, I agree, it would be nice to have more flexible schema while you're content is a work in progress.
Hello,
I have been using groqd for a while, and while implementing Sanity's preview mode, I realized most (if not all) fields end up being null in draft state (except for the slug). I think it would be pretty useful to have a way where everything is nullable by default. I understand the typescript could get kind of tricky with this but do you think either having a way to do this with declaration merging (not sure if it's possible) or maybe something similar to
grab$
but with a different symbol would be useful?The text was updated successfully, but these errors were encountered: