GROQ-JS is a (work-in-progress) JavaScript implementation of GROQ which follows the official specification.
import {parse, evaluate} from 'groq-js'
let input = '*[_type == "user"]{name}'
// Returns an ESTree-inspired syntax tree
let tree = parse(input)
let documents = [
{_type: "user", name: "Michael"},
{_type: "company", name: "Bluth Company"}
]
// Evaluate a tree against a set of documents
let result = await evaluate(tree, {documents})
Table of contents:
GROQ-JS is currently not yet released on NPM.com, but you can install the development version from Git:
# NPM
npm i git+https://git@github.com/sanity-io/groq-js.git
# Yarn
yarn add git+https://git@github.com/sanity-io/groq-js.git
Tests are written in Jest:
# Install dependencies
yarn
# Run tests
yarn test
You can also generate tests from the official GROQ test suite:
# Clone the repo somewhere:
git clone https://github.com/sanity-io/groq-test-suite somewhere
# Install dependencies:
(cd somewhere && yarn)
# Generate test file (in this repo):
./test/generate.sh somewhere
# Run tests as usual:
yarn test
GROQ-JS is currently not released.
MIT © Sanity.io