0

I have three schemas docTopics => subTopics => article that are references of each other.

I wanted to write a query for docTopics to return all the subTopics references to docTopics

export const queryRefrence = groq`
  {
    "topics": *[_type == "subTopics"] {
      _id,
      topic,
      title,
      id,
      "topics": docsTopics[] -> {title}
    }
  }`
 
sep
  • 29
  • 4

1 Answers1

1

After some research from the documentation. I was able to nest the subtopics inside of topics

"mainTopics":*[_type == "docsTopics"] | order(title) {
    title,
  "subTopics" : *[_type == "subTopics" && topic._ref == ^._id] | order(id) {
      title,
      slug,
      id
    } 
  }
sep
  • 29
  • 4