# groq

> Tagged template literal for Sanity.io GROQ-queries

Latest version **6.17.0** (published 2026-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install groq
pnpm add groq
yarn add groq
bun add groq
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.17.0 |
| Published | 2026-09-29 |
| First published | 2018-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.12 |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 6347 |
| Author | Sanity.io <hello@sanity.io> |
| Maintainers | kmelve, bjoerge, rexxars, skogsmaskin, mariuslundgard, sanity-svc.npm, sanity-io, simenss |
| Keywords | cms, content, groq, headless, literal, realtime, sanity, string, tagged, template |

## Links

- npm: https://www.npmjs.com/package/groq
- Repository: https://github.com/sanity-io/sanity
- Homepage: https://www.sanity.io/
- Issues: https://github.com/sanity-io/sanity/issues
- npm.io page: https://npm.io/package/groq

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 6.17.0 (latest) — 2026-09-29
- 6.18.0-next.35 (next) — 2026-10-05
- 6.15.0 (stable) — 2026-09-17
- 4.22.1 (maintenance-v4) — 2026-08-19
- 5.31.2 (maintenance-v5) — 2026-08-19
- 6.5.0-workbench.20260714145319 (workbench) — 2026-07-14
- 6.0.0-next-major.20260611102044 (next-major) — 2026-06-11
- 5.25.0-canary.20260507124900 (canary) — 2026-05-07
- 5.14.2-alpha.15 (alpha) — 2026-03-11
- 4.20.2-fix-tsa-expression-not-allowed.2.5e90622c2d (fix-tsa-expression-not-allowed) — 2025-12-04
- 4.20.2-fix-babel-traverse-bug.2.03a7495fed (fix-babel-traverse-bug) — 2025-12-04
- 4.1.2-rita-prerelease-ref.28 (rita-prerelease-ref) — 2025-07-24
- 4.1.2-4.2.0-rita-prerelease-tag.0.28 (4.2.0-rita-prerelease-tag.0) — 2025-07-23
- 4.1.1-bump-pkg-utils.6 (bump-pkg-utils) — 2025-07-22
- 3.99.1-bitter-lemon.5 (bitter-lemon) — 2025-07-18
- … 4229 more at https://npm.io/package/groq/versions

## README

# GROQ tagged template literal

This module exports a single function that can be called with an ES2015 [template string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) to signal that it represents a GROQ-query.

The result will be the exact same string as the input, - this is currently helpful for getting syntax highlighting in editors, but in the future it might also parse and validate queries, strip unncessary whitespace and similar.

Pairs well with [vscode-sanity](https://github.com/sanity-io/vscode-sanity)!

## Installing

```
npm install --save groq
```

## Usage

```js
import groq from 'groq'

const query = groq`*[_type == 'products'][0...10]`
```

## Automatic type inference

If you are using `@sanity/codegen` you can use `defineQuery` instead of `groq` to
get type inference out of the box:

```ts
import {defineQuery} from 'groq'

const query = defineQuery(`*[_type == 'products'][0...10]`)
```

In the future we might merge `defineQuery` with `groq`, but this is currently [not
100% supported by TypeScript](https://github.com/microsoft/TypeScript/issues/33304).

## What is Sanity? What is GROQ?

[Sanity](https://www.sanity.io) is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches.

To get started with Sanity, please head over to our [getting started guide](https://sanity.io/docs/introduction/getting-started)

## License

MIT-licensed. See LICENSE.

---
_Source: https://npm.io/package/groq · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
