FormidableLabs / groqd

A schema-unaware, runtime and type-safe query builder for GROQ.
https://commerce.nearform.com/open-source/groqd
MIT License
230 stars 16 forks source link

groq-builder: consistent null/undefined #299

Closed danteissaias closed 1 month ago

danteissaias commented 1 month ago

Is there an existing issue for this?

Code of Conduct

Question

groq-builder converts potentially undefined fields to potentially null in top level projections. However it doesn't change any types deeper into the query.

// Schema type
type Product = {
  _id: string;
  _type: "product";
  name?: string;
};

// Query
export const productsQuery = q.star
  .filter(...)
  .project((q) => ({
    products: q.field("products[]").deref(),
  }));

type ResultType = {
  products: Product[] | null;
}

Is this inconsistency between null and undefined intentional?