CLI Typegen expand references
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
Research direction
Start by locating the CLI typegen implementation and its typegen configuration handling. Review how schema references and GROQ query types currently produce internalGroqTypeReferenceTo, then determine how configuration or schema flags should control expansion and how multi-level references should be represented. Done means generated TypeScript types expose the referenced schema properties without requiring a dummy query.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
When generating types you only get an "internalGroqTypeReferenceTo" a related schema.
export type ProgressBar = {
_id: string;
_type: "progressBar";
_createdAt: string;
_updatedAt: string;
_rev: string;
name: string;
steps: Array<{
_ref: string;
_type: "reference";
_weak?: boolean;
_key: string;
[internalGroqTypeReferenceTo]?: "progressBarStep";
}>;
locale?: string;
};
This means that you can't access the actual properties on an indiviual "step", which becomes troublesome when you have several references to other schemas or some kind of multi-level-reference structure (e.g. I have a Page with a Progress bar that has Progress bar steps).
Describe the solution you'd like
It would be great if we during the type generation could define if we wanted all/some "internalGroqTypeReferences" expanded. Perhaps either via the typegen config or some kind of flag on the schema itself.
The result after such an expansion could be something like:
export type ProgressBar = {
_id: string;
_type: "progressBar";
_createdAt: string;
_updatedAt: string;
_rev: string;
name: string;
steps: Array<{
_ref: string;
_type: "reference";
_weak?: boolean;
_key: string;
[internalGroqTypeReferenceTo]?: "progressBarStep";
// Progress bar step properties
_id: string;
_type: "progressBarStep";
_createdAt: string;
_updatedAt: string;
_rev: string;
text: string;
percentage: number
locale?: string;
}>;
locale?: string;
};
Describe alternatives you've considered
I've considered creating a "dummy query" that explicitly expands the type but isn't used anywhere, however I don't think that's a very clean solution. I've also tried to alter the main query that contains multi-level-references to try and get the query-typegen to expand the "deeper levels of nesting" but with no success.
Additional context
Typegen is a super helpful feature, and the current state is a very promising! I do however think that there is room for some improvement, an this would bring it a big step forward!
- Dominant language
- TypeScript
- Stars
- 1
- Forks
- 2
- Avg merge
- 3d 11h
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sanity-io/codegen
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
-
Difficulty 5/5 Over a week Newbie friendliness 42/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
All issues in sanity-io/codegen
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·