-
Notifications
You must be signed in to change notification settings - Fork 6
PoC: Strongly-typed schema #201
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
Comments
Key Findings from PoCA PoC was created in this branch: sanity-typed API changes to support strong typesI was able to leave the GroqD API intact, with only 2 notable changes
Effectiveness of this APIFor the most part, strongly-typed schema gives a GREAT developer experience!
PerformanceThis might be a prohibiting factor.
WorkaroundsThe shape of the inferred schema is pretty basic: Simplified Example Schemaexport type SanitySchemaCompiled = {
category: {
slug: { _type: "slug"; current: string };
name: string;
description: string;
};
product: {
slug: { _type: "slug"; current: string };
name: string;
description: string;
categories?: Array<{
_type: "reference";
_ref: string;
[_referenced]: "category";
}>;
};
};
Massive Performance Improvement by listing documentsInstead of inferring all types from the entire // export type SanitySchema = InferSchemaValues<typeof config>;
export type SanitySchema = {
category: InferRawValue<typeof category>;
categoryImage: InferRawValue<typeof categoryImage>;
description: InferRawValue<typeof description>;
flavour: InferRawValue<typeof flavour>;
product: InferRawValue<typeof product>;
productImage: InferRawValue<typeof productImage>;
siteSettings: InferRawValue<typeof siteSettings>;
style: InferRawValue<typeof style>;
variant: InferRawValue<typeof variant>;
}; Follow-up tasksAfter working through this PoC, Grant and I had a discussion that led to an interesting conclusion.
So, this conclusion is leading us to a follow-up PoC -- making Zod optional/swappable, and relying on Schema types and static type checks instead of runtime checks! See #202. |
Update: this has been implemented as the |
GroqD currently supports strongly-typed output types.
However, it is completely unaware of the input types as defined in the Sanity Schema.
Here are some tasks for creating a POC for strongly-typed input types:
@sanity-typed/types
q
that's bound to this schemaAPI methods to make strongly-typed:
q
filter
filterByType
grab
grab$
grabOne
grabOne$
select
slice
order
deref
score
nullable
The text was updated successfully, but these errors were encountered: