Can the results of a query in documentList be reused inside the function?

3 replies
Last updated: Sep 19, 2020
Can the results of a query in
documentList
be reused inside the function? For example, I’d like the title here to say like “13 Properties with Inspection Times” or whatever the count of the query is…

S.documentList()
  .schemaType('property')
  .title('Properties with Inspection Times')
  .filter(
      '_type == "property" && count(inspectionTimes) > 0'
  )
Sep 19, 2020, 7:34 AM
That’s not possible at the moment. But since you can run promises/observables, you can do the query in the structure builder… structure and use the data where you need it.
Here’s an example where we fetch counts in the icons:
https://sanity-io.slack.com/archives/CGKNRPC80/p1593460636120200?thread_ts=1593460050.120000&cid=CGKNRPC80
And another where we use the documentstore to list out tickets by their tags (that can be adapted to your use case):
https://github.com/sanity-io/community-studio/blob/master/deskStructure.js#L143
Sep 19, 2020, 9:11 AM
That’s not possible at the moment. But since you can run promises/observables, you can do the query in the structure builder… structure and use the data where you need it.
Here’s an example where we fetch counts in the icons:
https://sanity-io.slack.com/archives/CGKNRPC80/p1593460636120200?thread_ts=1593460050.120000&cid=CGKNRPC80
And another where we use the documentstore to list out tickets by their tags (that can be adapted to your use case):
https://github.com/sanity-io/community-studio/blob/master/deskStructure.js#L143
Sep 19, 2020, 9:11 AM
Okay cool. Yeah after posting I figured maybe I could do the query elsewhere and pass in the results that way. These code examples help, thanks!
Sep 19, 2020, 9:13 AM

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?