GitHub
Twitter

Query Parser

The power of data at your fingertips

Rack & Pinion's Query Parser uses Objectified GROQ syntax for queries as well as GROQ strings. Under the hood uses primarily the former.

// GROQ
*[_type == 'post' && slug.current == $slug] {
title,
image->
category->{
...,
title
},
'related': *[_type == 'post'][0..2]{_id, title, path, image {..., asset->}}
}
// R&P query
getDoc('post', {
filters: ['slug.current == $slug'],
params: { slug },
projections: {
related: `*[_type == 'post' && slug.current != $slug][0..2]{_id, title, path, image {..., asset->}}`,
},
});
// Or written out...
getDoc('post', {
filters: ['slug.current == $slug'],
params: { slug },
projections: {
title: true,
image: '->',
category: {
'...': true,
title: true,
},
related: `*[_type == 'post'][0..2]{_id, title, path, image {..., asset->}}`,
},
});
// Alternative
getDoc('post', {
filters: ['slug.current == $slug'],
params: { slug },
projections: ` title, image->, category: { ..., title, }, related: *[_type == 'post'][0..2]{_id, title, path, image {..., asset->}}, `,
});
💡
See something that is out of date or that could be improved?Please let the team know!1. You can create a Github issue2. Pull down the repo and create a PR with your suggested changes implimented.3. Or just let someone know in the R&P Slack Channel.We love making things better.