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->}},
`,
});