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
Recently found this library after struggling with groq typing forever and so far I'm loving it!
During use I found a bug, I assume, that is related to what happens to image data between the sanity client returning and the groq-builder query returning.
constGRID_FRAGMENT=q.fragment<Grid>().project((p)=>({_type: z.literal('grid'),items: p.field('items[]').project((p)=>({_key: z.string(),
...p.conditionalByType({feature: FEATURE_FRAGMENT,// Working fragmentimage: {asset: true,alt: true},// Image projection}),})),}));constQUERY=q.parameters<{slug: string}>().star.filterByType('page').filterBy('slug.current == $slug').slice(0).project((p)=>({content: p.field('content[]').project((p)=>({_key: z.string(),
...p.conditionalByType({grid: GRID_FRAGMENT,// Here is where the grid schema/fragment is referenced}),})),}));constpage=awaitrunQuery(QUERY,{parameters: {slug: '...'}});
I receive the following back from the sanity client (raw):
{
"content": [
{
"_key": "0959152d2389",
"_type": "grid",
"items": [
{
"_key": "cf3b123386aa",
"_type": "image"// Where did asset and alt go?
},
{
"_key": "f3ba7c857962",
"_type": "heading",
...
}
]
},
...
]
}
As you can see, the reult from runQuery removed the asset and alt properties of the image type from the value originally returned from the sanity client.
Using InferResultType to get the return type of the query appears to show the correct types, including the asset and alt properties.
Interestingly though, if I replace
image: {asset: true,alt: true}
with
image: {asset: true,alt: z.string()}
then asset and alt are properly inlcuded in the query result, which leads me to believe there is something going on with the parsing logic in between the client return and the query return.
So far I have only run into this issue when projecting image properties inside of a p.conditionalByType({...}) call.
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Code of Conduct
Code Sandbox link
No response
Bug report
Recently found this library after struggling with groq typing forever and so far I'm loving it!
During use I found a bug, I assume, that is related to what happens to image data between the sanity client returning and the groq-builder query returning.
Given the following schema:
And the following query builder:
I receive the following back from the sanity client (raw):
And this back from
runQuery
(groq-builder)As you can see, the reult from
runQuery
removed theasset
andalt
properties of theimage
type from the value originally returned from the sanity client.Using
InferResultType
to get the return type of the query appears to show the correct types, including theasset
andalt
properties.Interestingly though, if I replace
with
then
asset
andalt
are properly inlcuded in the query result, which leads me to believe there is something going on with the parsing logic in between the client return and the query return.So far I have only run into this issue when projecting
image
properties inside of ap.conditionalByType({...})
call.The text was updated successfully, but these errors were encountered: