Query by ID or UID

This page gives examples of how to query for a document either by its ID or its UID with the Prismic GraphQL API.


If you have multiple languages

Note that if you are trying to query a document that isn't in the master language of your repository, you will need to specify the language code or wildcard language value. You can read how to do this on the Query by language page.

Query by ID

Since IDs are global fields, you will be able to find the document you want using the id argument.

Here is an example that shows how to query the Blog document with the id "WmYKByYAACQAzLqk".

Copy
query{
  allBlogs(id:"WmYKByYAACQAzLqk"){
    edges{
      node{
        title
        description
      }
    }
  }
}

Query by multiple IDs

In order to query documents that include the specified IDs, use the id_in argument with an array of strings.

For example, here is a query that will retrieve the two Blog documents that match the IDs: "WmYKByYAACQAzLqk" and "XyHEcBEAACUAt3AE".

Copy
query{
  allBlogs(id_in:["WmYKByYAACQAzLqk", "XyHEcBEAACUAt3AE"]){
    edges{
      node{
        title
        description
      }
    }
  }
}

Query by UID

If you setup your custom type to have a UID field, you will be able to filter your results based on the UID value using the uid argument.

Here is an example that will query the Blog document with the UID value of "graphql-api".

Copy
query{
  allBlogs(uid:"graphql-api"){
    edges{
      node{
        title
        description
      }
    }
  }
}

Query by multiple UIDs

If you want to query documents that include specific UIDs, use the uid_in argument with an array of strings.
In this example, the query will retrieve the two Blog documents that match the passed UIDs: "music", "vlogs" and "illustrators".

Copy
query{
  allBlogs(uid_in:["music", "vlogs", "illustrators"]){
    edges{
      node{
        title
        description
      }
    }
  }
}