FormidableLabs / groqd

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

groq-builder: add Sanity Codegen / Typegen documentation #285

Open scottrippey opened 6 months ago

scottrippey commented 6 months ago

Is there an existing issue for this?

Code of Conduct

Feature Request

Sanity Codegen / Typegen has been released, and is now the official, recommended way to generate Sanity schema types for consumption by groq-builder.

Currently, the documentation still lists the `ts-simplify` + `@sanity-typed/types` approach.  

While this is viable, the Sanity Codegen generated types have several advantages:
- Performance
- Simplicity
- Future-proof
- Better Developer Experience (named types, etc)

We need to update the documentation to showcase how to use Sanity Codegen together with `groq-builder`.
danteissaias commented 5 months ago

The way references are handled in deref() has to be updated to support [internalGroqTypeReferenceTo] being undefined. Sanity's typegen makes them all optional.

asset?: {
  _ref: string;
  _type: "reference";
  _weak?: boolean;
  [internalGroqTypeReferenceTo]?: "sanity.imageAsset";
};