Query all documents

This page shows examples of how to query all the documents in your Prismic repository.


The _allDocuments operation

By definition the GraphQL API will require you to define the fields that you want to retrieve.

With the _allDocuments query field, the API will return all the documents in your repository. Since each custom type has different fields, you need to define which field you want to retrieve for a specific custom type. The only exception is the metadata which is the same for all documents regardless of the type.

Let's first look at how to retrieve the metadata.

Retrieve the metadata

If you want to have access to the metadata, you can directly retrieve it using the _meta field. In the example below we will retrieve the ID, UID, and the type of all the documents.

Copy
query{
  _allDocuments{
    edges{
      node{
        _meta{
          id
          uid
          type
        }
      }
    }
  }
}

Retrieve content fields

Every Custom Type in your repository might have different fields, so we will need to use a switch to define which fields to retrieve depending on the type.

The example below shows how to retrieve the "title" field from all Blog documents and the "name" field from all the Author documents. It also retrieves some metadata from all documents.

Copy
query{
  _allDocuments{
    edges{
      node{
        ... on Blog{
          title
        }
        ... on Author{
          name
        }
        _meta{
          id
          uid
          type
        }
      }
    }
  }
}

Note that the results won't be limited to the types specified in the switch. The switch will only determine which fields are returned for a given type.

Pagination

It's worth noting that the GraphQL API will automatically paginate your results to 20 items. If you have more than 20 documents that you are trying to retrieve, then you will need to run more than one query to retrieve it all. Check out our page about Pagination to learn more.