ricokahler / sanity-codegen

Generate TypeScript types from your Sanity.io schemas
sanity-codegen-dev.vercel.app
MIT License
270 stars 19 forks source link

fix(v1): handle `_key` and `_type` in objects #294

Open ochicf opened 1 year ago

ochicf commented 1 year ago

Fixes https://github.com/ricokahler/sanity-codegen/issues/236

The strategy taken has been to recursively forward an ancestors array so the parent is available when generating the types for a node. Ff current node is object and parent is array, then it add _key and _type.

Let me know if those fields should be added in any other cases.

Also @ricokahler I'm not able to run tests, so I have not updated them. But I think it would be good to add a case to ensure this is kept on future refactors/changes.

vercel[bot] commented 1 year ago

@ochicf is attempting to deploy a commit to the Rico Kahler Team on Vercel.

A member of the Team first needs to authorize it.

MurmeltierS commented 1 year ago

this seems very much needed .__.

@ochicf any chance you are already publishing a fixed version somewhere for the moment

ochicf commented 1 year ago

this seems very much needed .__.

@ochicf any chance you are already publishing a fixed version somewhere for the moment

Hey @MurmeltierS. I have integrated all my PRs into this branch: https://github.com/OrigenStudio/sanity-codegen/tree/release/v1.0.0-alpha.next

You could take that branch, build the packages I've changed (looked for bumped versions in the package.json) and publish it to a local installation of Verdaccio. Then you can install the package pointing to your local registry so it's installed from there. It's how I'm doing it to generate the types locally.

I'm wondering aswell if it could be possible to install it directly from GitHub? I have never tried it so not sure if can be done, but I guess even if possible, it will be complicated as it's a monorepo with multiple packages inside 🤔

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sanity-codegen-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2023 2:09pm
phmasek commented 1 year ago

Nice work @ochicf! ⭐ Would be really helpful to have this one merged.

maximilianschmitt commented 1 year ago

This is great, I also need this! Thank you!

michelebruno commented 11 months ago

This would be a huge improvement! @ricokahler any chance this could be merged please?

shreyansqt commented 8 months ago

@ricokahler this would a much needed feature. Do you think you can review this PR?