Package Exports
- @sanity/groq-store
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sanity/groq-store) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@sanity/groq-store
In-memory GROQ store. Streams all available documents from Sanity into an in-memory database and allows you to query them there.
Targets
- Node.js >= 10
- Modern browsers (Edge >= 14, Chrome, Safari, Firefox etc)
Caveats
- Streams entire dataset to memory, so generally not recommended for large datasets
- Does not work with tokens in browser (currently)
Installation
npm install --save @sanity/groq-storeUsage
import {groqStore, groq} from '@sanity/groq-store'
const store = groqStore({
projectId: 'abc123',
dataset: 'blog',
// Keep dataset up to date with remote changes. Default: false
listen: true,
// "Replaces" published documents with drafts, if available.
// Note that document IDs will not reflect draft status, currently
overlayDrafts: true,
// Optional token, if you want to receive drafts, or read data from private datasets
// NOTE: Does _not_ work in browsers yet
token: 'someAuthToken',
})
store.query(groq`*[_type == "author"]`).then((docs) => {
console.log(docs)
})
store.getDocument('grrm').then((grrm) => {
console.log(grrm)
})
store.getDocuments(['grrm', 'jrrt']).then(([grrm, jrrt]) => {
console.log(grrm, jrrt)
})
const sub = store.subscribe(
groq`*[_type == $type][] {name}`, // Query
{type: 'author'}, // Params
(result) => console.log(result)
)
// Later, to close subscription:
sub.unsubscribe()
// Later, to close listener:
store.close()License
MIT © Sanity.io