JSFiddle - React, Tailwind, and code Playground
JavaScript
function nestedParentFragment(count = 10) {
return `
"slug": slug[$locale].current,
parent-> {
"slug": slug[$locale].current,
${count > 0 ? nestedParentFragment(count - 1) : ""}
}`;
}
const redirectsQuery = `
*[_type == "redirect" && enabled == true] {
source,
destinationLocale,
destination->{
${nestedParentFragment(10)}
}
}
`;
body.innerHTML = redirectsQuery;