Package Exports
- groq-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 (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
GROQ-JS
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 value = await evaluate(tree, {documents})
// Gather everything into one JavaScript object
let result = await value.get()
console.log(result)
Table of contents:
Installation
GROQ-JS is currently not yet released on NPM.com, but you can install the development version from Git:
# NPM
npm i groq-js
# Yarn
yarn add groq-js
Documentation
See API.md for the public API.
Versioning
GROQ-JS follows SemVer and is currently at version v0.1. This is an "experimental" release and anything may change at any time, but we're trying to keep changes as minimal as possible:
- The public API of the parser/evaluator will most likely stay the same in future version.
- The syntax tree is not considered a public API and may change at any time.
- This package always implements the latest version of GROQ according to the specification.
- The goal is to release a v1.0.0 by the end of 2019.
License
MIT © Sanity.io
Tests
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