Gathering detailed insights and metrics for sanity-typed-queries
Gathering detailed insights and metrics for sanity-typed-queries
Gathering detailed insights and metrics for sanity-typed-queries
Gathering detailed insights and metrics for sanity-typed-queries
@liammartens/sanity-typed-queries
A collection of helper functions to improve the typing of Sanity resources.
@freighter-studio/sanity-typed-queries
A collection of helper functions to improve the typing of Sanity resources.
groq-builder
A **schema-aware**, strongly-typed GROQ query builder. It enables you to build GROQ queries using **auto-completion**, **type-checking**, and **runtime validation**.
@danteissaias/groq-builder
A **schema-aware**, strongly-typed GROQ query builder. It enables you to build GROQ queries using **auto-completion**, **type-checking**, and **runtime validation**.
A typed, zero-dependency schema generator and query builder for Sanity.
npm install sanity-typed-queries
Typescript
Module System
Node Version
NPM Version
TypeScript (98.97%)
JavaScript (1.03%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
178 Stars
865 Commits
7 Forks
3 Watchers
4 Branches
4 Contributors
Updated on Jul 14, 2025
Latest Version
0.9.5
Package Id
sanity-typed-queries@0.9.5
Unpacked Size
54.38 kB
Size
12.77 kB
File Count
6
NPM Version
9.7.2
Node Version
20.3.1
Published on
Aug 14, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A typed query generator for Sanity
A zero-dependency schema generator and query builder that is fully-typed and works in JavaScript and TypeScript.
"prop": my.prop
)Help and contributions are welcome.
First install sanity-typed-queries
:
1yarn add sanity-typed-queries 2 3# or npm 4 5npm install sanity-typed-queries --save
Now you will need to generate your Sanity schema documents using the schema builder. You will get documentation as you type, and enforced compliance with Sanity's schema builder, such as being able to see validation rules applicable to the type of field you are creating, and so on.
schema/author.js
:
1import { defineDocument } from 'sanity-typed-queries' 2 3const { document } = defineDocument('author', { 4 name: { 5 type: 'string', 6 validation: Rule => Rule.required(), 7 }, 8 biography: { 9 type: 'text', 10 rows: 4, 11 }, 12 yearOfBirth: { 13 type: 'number', 14 }, 15}) 16 17export default document
This is equivalent to defining the following schema:
1export default { 2 name: 'author', 3 title: 'Author', 4 type: 'document', 5 fields: [ 6 { 7 name: 'name', 8 title: 'Name', 9 type: 'string', 10 validation: Rule => Rule.required(), 11 }, 12 { 13 name: 'biography', 14 title: 'Biography', 15 type: 'text', 16 rows: 4, 17 }, 18 { 19 name: 'yearOfBirth', 20 title: 'Year Of Birth', 21 type: 'number', 22 }, 23 ], 24}
For more documentation, see this GROQ/query builder cheat sheet.
You can also export a query builder from the same file.
1import { defineDocument } from 'sanity-typed-queries' 2 3const { document, builder } = defineDocument('author', { 4 ... 5}) 6 7// Export your query builder for use elsewhere 8export { builder } 9export default document
You can use this builder elsewhere to generate the appropriate types and GROQ queries. For example:
1import { builder as authorBuilder } from './cms/schema/author.js' 2 3const [query, type] = authorBuilder.pick('name').first().use() 4 5// *[_type == 'author'][0].name 6const queryString = query 7 8// string 9type AuthorName = typeof type
If you're using the Sanity client, you might use it like this:
1import sanityClient from '@sanity/client' 2import { author } from './cms/schema/author.js' 3 4const [query, type] = author.pick('name').first().use() 5 6const client = sanityClient(config) 7// Promise<string> 8const result = client.fetch<typeof type>(query)
You can export utility objects or documents for reference within other schemas.
schema/tag.js
:
1import { defineObject } from 'sanity-typed-queries' 2 3const { tag, object } = defineObject('tag', { 4 ... 5}) 6 7export { tag } 8export default object
Then you can pass that when defining documents that reference it.
schema/author.js
:
1import { defineObject } from 'sanity-typed-queries' 2import { tag } from './tag' 3 4const { builder, document } = defineDocument( 5 'author', 6 { 7 tag: { 8 type: 'tag', 9 }, 10 }, 11 [tag] 12) 13 14export default document
Projects I've found helpful are:
This has been developed to suit my needs but additional use cases and contributions are very welcome.
MIT License - Copyright © Daniel Roe
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
1 existing vulnerabilities detected
Details
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More