Skip to content
main
Switch branches/tags
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 dataset = [
  {_type: 'user', name: 'Michael'},
  {_type: 'company', name: 'Bluth Company'}
]

// Evaluate a tree against a dataset
let value = await evaluate(tree, {dataset})

// Gather everything into one JavaScript object
let result = await value.get()

console.log(result)

Table of contents:

Installation

# 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.2. See the changelog for recent changes. 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 2020.

License

MIT © Sanity.io

Tests

Tests are written in Jest:

# Install dependencies
npm i

# Run tests
npm test

You can also generate tests from the official GROQ test suite:

# Fecth and generate test file:
./test/generate.sh

# Run tests as usual:
npm test