Getting a list of all tags of a type using graphql in Gatsby

Hi,

I've been searching the documentation to find a way to query all tags used for my custom_type, but I have had no luck. I could just retrieve everything and iterate and find all the tags, but I was hoping there was a more efficient way of getting this info.

Thanks in advanced.

Hello @adam3, welcome to the community!

It isn't possible to know which tags are using certain Custom Types. But you can get the list of all the tags in your repository.

Currently, you can get this list by hitting the nd endpoint of your repository. If you go to https:/your-repo-name.cdn.prismic.io/api/v2 you'll get a JSON object with the metadata info of your repo including, the ref, the languages, and a tags property that contains an array of your tags.

Soon, this will get replaced with a new dedicated endpoint that we're currently working on. It'll allow you to get all tags.

For now, you can continue working with the current way of getting the tags.

Hi thanks for the response.

I found that data and that is what I am looking for. However, how would I get this using graphql and the gatsby prismic plugin. It is my first time using graphql and I dont see it will work within the gatsby configuration.

I checked with the team, and this is possible with the gatsby source plugin!
You need to use the distinct field in your queries.

Here's an example. This query gets all tags for the documents of the type Page:

query MyQuery {
  allPrismicPage {
    distinct(field: tags)
  }
}
1 Like

Thanks, I'll give it a try!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.