FormidableLabs / FormidableLabs/groqd
`.raw` projection is not working correctly
- Dominant language
- TypeScript
- Stars
- 293
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Description
### 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
### Code Sandbox link
_No response_
### Bug report
Hello, thank you for this amazing lib. V1 is fab!
I've got a schema where I am trying to work out a distance so I am using `raw(...)` so that I can use the `geo::distance` function. My query is returning an error:
```
const itemsQuery = q.star
.filterByType("item")
.project(() => ({
location: true,
distance: q.raw(
"coalesce(geo::distance(location, geo::latLng(1.234, -1.234)), 0)",
q.number(),
),
}));
```
The error is:
`result.distance: Required`
I have wrapped it in a coalesce to see if that fixed it as not all `location` values are set, so want to default to `0` where that is the case, but that still has an error.
When I log out the actual query and paste it into the vision plugin it works perfectly, and all results have a numerical value.
```
*[_type == "item"] { location, "distance": coalesce(geo::distance(location, geo::latLng(1.234, -1.234)), 0) }
```
The generated type when viewed in my IDE is:
```
GroqBuilder<{ location: Geopoint | null; distance: number }[], SchemaConfig>
```
As a related issue. When I have a raw field I can't then chain an `order` of any field to the query and get the error:
```
Error: You cannot chain a new query once you've specified a parser, since this changes the result type.
```
Thank you for your help :)
Contributor guide
Assessment
This issue has not been assessed yet.