Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@sanity-typed/groq-zod #306

Closed
saiichihashimoto opened this issue Sep 7, 2023 · 4 comments
Closed

@sanity-typed/groq-zod #306

saiichihashimoto opened this issue Sep 7, 2023 · 4 comments

Comments

@saiichihashimoto
Copy link
Owner

A schema aware GROQ zod parser would need:

GROQ Zod Parser
= typed runtime ast to zod parser(typed runtime schema, typed runtime groq parsed ast)
= typed runtime ast to zod parser(@sanity-typed/types, @sanity-typed/groq-js)

Is this not technically possible? We have typed runtime values for everything we'd need to generate a zod parser for GROQ queries.

@saiichihashimoto saiichihashimoto pinned this issue Sep 7, 2023
@saiichihashimoto saiichihashimoto changed the title GROQ-zod @sanity-typed/groq-zod Sep 22, 2023
@saiichihashimoto
Copy link
Owner Author

@saiichihashimoto
Copy link
Owner Author

This is... so complicated. Picking apart any zod schema to transform it is very difficult (and sometimes impossible). The fact that @sanity-typed/zod does refinements that create ZodEffects immediately makes this challenging.

@saiichihashimoto
Copy link
Owner Author

I don't think I'm going to do this.

  • There's no really good way to pick apart zod schemas, arbitrarily. For example, a ZodObject with a few refinements and an intersection immediately becomes un-pickable, let alone able to be transformed with a GROQ projection.
  • We'd need an intermediate schema representation of a type that we'd be able to transform like that
  • Sanity's schemas wouldn't work for that representation, since there's datatypes involved not represented, so we'd have to create it from scratch (or use some third party one although it would need to preserving type safety throughout transformations).
  • Regardless, we'd have to translate sanity's schema types to that representation, just like we did for @sanity-typed/zod or @sanity-typed/faker, which sounds exhausting.

It's definitely possible. But the scope of this rivals the scope of the rest of the monorepo, possibly even more. I'm not doing that. It's still within the vision, but I definitely can't justify actually spending time on that.

@saiichihashimoto saiichihashimoto closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2023
@saiichihashimoto saiichihashimoto changed the title @sanity-typed/groq-zod [Abandoned] @sanity-typed/groq-zod Oct 3, 2023
@saiichihashimoto saiichihashimoto changed the title [Abandoned] @sanity-typed/groq-zod @sanity-typed/groq-zod Dec 15, 2023
@saiichihashimoto
Copy link
Owner Author

https://www.npmjs.com/package/groq-builder is definitely my recommended solution atm, so go look there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant