Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
sanity-generator
Advanced tools
Sanity Generator is a codegen tool for [Sanity](https://www.sanity.io) to automatically generate GROQ queries from a schema perspective.
Sanity Generator is a codegen tool for Sanity to automatically generate GROQ queries from a schema perspective.
Note: Currently in beta. Be cautious when using it in production.
To get started, define your document schemas and queries like this:
// sanity-generator.config.ts
export default createConfig({
schemas: {
page: pageSchema,
},
queries: {
getPages: ({ schemas }) => /* groq */ `
*[_type == "${schemas.page.name}"] {
${schemas.page.projection}
}
`,
},
});
When you run $ npx sanity-generator
, it creates queries with a spread operator to return all fields.
// sanity-generator/queries/getPages.ts
export const getPages = /* groq */ `
*[_type == "page"] {
...
}
`
Define resolvers for field types from your Sanity schema. These resolvers are functions that return custom GROQ projections:
// sanity-generator.config.ts
export default createConfig({
schemas: {
page: pageSchema,
},
resolvers: {
// Resolve all field types of "localString" with this projection...
localeString: (name: string) => /* groq */ `
"${name}": coalesce(${name}[$lang], ${name}.en)
`,
},
queries: {
getPages: ({ schemas }) => /* groq */ `
*[_type == "${schemas.page.name}"] {
${schemas.page.projection}
}
`,
},
});
If you run $ npx sanity-generator
now, it expands the projection to transform all types with their associated resolver:
// sanity-generator/queries/getPages.ts
export const getPages = /* groq */ `
*[_type == "page"] {
...,
"seoTitle": coalesce(seoTitle[$lang], seoTitle.en),
sections[] {
...,
gallerySection {
...,
slides[] {
...,
slide {
...,
"title": coalesce(title[$lang], title.en)
}
}
}
}
}
`
FAQs
Sanity Generator is a codegen tool for [Sanity](https://www.sanity.io) to automatically generate GROQ queries from a schema perspective.
The npm package sanity-generator receives a total of 0 weekly downloads. As such, sanity-generator popularity was classified as not popular.
We found that sanity-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.