Skip to content

Add GROQ language support#7914

Open
rexxars wants to merge 1 commit intogithub-linguist:mainfrom
sanity-io:feat/add-groq-language
Open

Add GROQ language support#7914
rexxars wants to merge 1 commit intogithub-linguist:mainfrom
sanity-io:feat/add-groq-language

Conversation

@rexxars
Copy link
Copy Markdown

@rexxars rexxars commented Apr 13, 2026

Add GROQ (Graph-Relational Object Queries) as a recognized data language with syntax highlighting for .groq files, JS/TS template literal injection, and markdown code block injection.

  • Grammar source: sanity-io/groq-syntax (textmate-groq) (MIT licensed)
  • Scopes: source.groq, groq-injection.js, groq-injection.markdown
  • Samples: blog query, product filter, site navigation

Description

GROQ is an open query language for JSON-like data, created by Sanity.io and published under the OWFa 1.0 license since 2019. It is purpose-built for querying and transforming content in document stores, with first-class support for references, projections, and filtering.

GROQ is widely used across the Sanity ecosystem, which includes companies like Nike, Figma, Cloudflare, Spotify, Shopify, and Riot Games. The groq npm package sees 800k+ weekly downloads (24M+ annually).

While .groq files represent one surface for the language, the majority of GROQ is written as tagged template literals in JavaScript/TypeScript (groq`*[_type == "post"]`) and in markdown code blocks (```groq). The grammar source (sanity-io/groq-syntax) provides injection grammars for both of these, following the same pattern as GraphQL in Linguist (inline.graphql, inline.graphql.markdown.codeblock via graphql/graphiql).

An ace mode recently landed as well, so this PR is also set to use that.

Usage evidence

Signal Count Search
groq template literals in TS 3,400+ files search
groq template literals in JS 2,100+ files search
```groq markdown blocks 630+ files search
import groq in JS/TS 2,600+ files search
.groq files (excl. forks) 200+ files / 40+ repos search

The .groq extension meets the 200-file threshold for extensions that typically occur once per repository (like Makefile). The results show broad distribution across independent users and organizations - not concentrated in Sanity's own repos.

The broader surface (5,500+ template literal files, 630+ markdown code blocks) demonstrates that the community already treats GROQ as a distinct language deserving syntax highlighting.

VS Code extension

The Sanity VS Code extension has 50,000+ installs and has provided GROQ syntax highlighting since 2018. The grammar was recently extracted to a dedicated repo (sanity-io/groq-syntax) to support multiple editors and Linguist integration.

Checklist:

  • I am adding a new language.
    • The extension of the new language is used in hundreds of repositories on GitHub.com.
    • I have included a real-world usage sample for all extensions added in this PR:
      • Sample source(s):
        • Samples written for this PR, representative of common GROQ patterns (content queries with references, faceted filtering with parameters, conditional projections)
      • Sample license(s): MIT (same as Linguist)
    • I have included a syntax highlighting grammar: https://github.com/sanity-io/groq-syntax
    • I have added a color
      • Hex value: #fa84ff
      • Rationale: Magenta from GROQ's brand palette.
    • I have updated the heuristics to distinguish my language from others using the same extension.
      Not needed - .groq is not used by any other language.

@rexxars rexxars requested a review from a team as a code owner April 13, 2026 15:14
@rexxars rexxars force-pushed the feat/add-groq-language branch from 0cd62ab to 735624c Compare April 21, 2026 20:50
@rexxars
Copy link
Copy Markdown
Author

rexxars commented Apr 21, 2026

Updated with ace_mode set to groq since it has now landed

Add GROQ (Graph-Relational Object Queries) as a recognized data language
with syntax highlighting for .groq files, JS/TS template literal injection,
and markdown code block injection.

- Grammar source: sanity-io/groq-syntax (MIT licensed)
- Scopes: source.groq, groq-injection.js, groq-injection.markdown
- Samples: blog query, product filter, site navigation
@rexxars rexxars force-pushed the feat/add-groq-language branch from 735624c to 23e3eb1 Compare May 2, 2026 03:15
@rexxars
Copy link
Copy Markdown
Author

rexxars commented May 2, 2026

Fixed the incorrect sort order in vendor/README.md that was causing the previous test run to fail

@lildude
Copy link
Copy Markdown
Member

lildude commented May 2, 2026

Fixed the incorrect sort order in vendor/README.md that was causing the previous test run to fail

🤔 The fact you had to do this suggests that you might not have used the script to add your grammar as detailed in the CONTRIBUTING.md file as it does it for you.

@rexxars
Copy link
Copy Markdown
Author

rexxars commented May 3, 2026

🤔 The fact you had to do this suggests that you might not have used the script to add your grammar as detailed in the CONTRIBUTING.md file as it does it for you.

I was having trouble with the docker image not wanting to be run on ARMv8, and then some issues with ruby versions etc. Originally I just read what those scripts did and manually did the same steps, but just went through and forced amd64 architecture for the docker images and resolved the ruby version issues - output is the same as in the PR though (minus the extensions for js/markdown)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants