All Projects → sanity-io → Groq Js

sanity-io / Groq Js

Licence: mit
JavaScript implementation of GROQ, the query language

Programming Languages

javascript
184084 projects - #8 most used programming language

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].