Skip to content

.raw projection is not working correctly #343

Open
@Designer023

Description

@Designer023

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • 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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggroqd-v1Related to the newer `v1.x` packageneeds-more-infoNeeds more information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions