Package Exports
- @sanity-typed/groq-js
- @sanity-typed/groq-js/dist/index.js
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-typed/groq-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@sanity-typed/groq-js
Typed GROQ-JS Results, all inferred, no query changes!
Page Contents
Install
npm install groq-js @sanity-typed/groq-js
Usage
Use parse
and evaluate
exactly as you would from groq-js
. Then, use the results with the typescript types!
// import { evaluate, parse } from "groq-js";
import { evaluate, parse } from "@sanity-typed/groq-js";
const input = '*[_type == "user"]{name}';
const tree = parse(input);
/**
* typeof tree === {
* type: "Projection";
* base: {
* type: "Filter";
* base: {
* type: "Everything";
* };
* expr: {
* type: "OpCall";
* op: "==";
* left: {
* name: "_type";
* type: "AccessAttribute";
* };
* right: {
* type: "Value";
* value: "user";
* };
* };
* };
* expr: {
* type: "Object";
* attributes: [{
* type: "ObjectAttributeValue";
* name: "name";
* value: {
* type: "AccessAttribute";
* name: "name";
* };
* }];
* };
* }
*/
const dataset = [
{ _type: "user", name: "Michael" },
{ _type: "company", name: "Bluth Company" },
] as const;
const value = await evaluate(tree, { dataset });
const result = await value.get();
/**
* typeof result === {
* name: "Michael";
* }[]
*/