Query by tags

This page gives you an explanation and examples of how to query documents by their tags by using the tags or tags_in arguments.


Query by a single tag

In this example we will query all the Blog documents with the the tag "Prismic". Then we retrieve a Title Text field that has the API ID of "title" and the meta data with the tags:

Copy
query{
  allBlogs(tags:"Prismic"){
    edges{
      node{
        title
        _meta{
          tags
        }
      }
    }
  }
}

Query by multiple tags

When querying by multiple tags, there are two options. One where you return the documents that have all of the tags and another where you return the documents that include any of the tags.

Documents that include all tags

In order to query documents that include all the tags specified, use the tags argument with an array of strings. For example, here is a query that will retrieve all the Blog documents that contain the tag "Prismic" and the tag "New Feature". Then we retrieve a Title Text field that has the API ID of "title" and the meta data with the tags:

Copy
query{
  allBlogs(tags:["Prismic", "New Feature"]){
    edges{
      node{
        title
        _meta{
          tags
        }
      }
    }
  }
}

Documents that include any tags

In order to query documents that include any the tags specified, use the tags_in argument with an array of strings. For example, here is a query that will retrieve all the Blog documents that contain the tag "Prismic" or the tag "New Feature". Then we retrieve a Title Text field that has the API ID of "title" and the meta data with the tags:

Copy
query{
  allBlogs(tags_in:["Prismic", "New Feature"]){
    edges{
      node{
        title
        _meta{
          tags
        }
      }
    }
  }
}