Is there a way to query for a record that saved but not published yet?

I’m working on project where there is a preview link for the content editor to a website that will show what it looks like before the click publish. How do I use a graphql query to query a record not yet published? I would think _status would equal draft but it doesn’t seem to be working, thanks.

query MyQuery {
  allProductInformationArticles(filter: {_status: {eq: draft}}) {
    id
    title
    series
    important
    country
    _publishedAt
    productImage {
      url
      alt
    }
    content {
      ... on ProductTechnicalSpecificationRecord {
        title
        list
      }
      ... on ProductDescriptionRecord {
        id
        title
        productDescription
      }
      ... on ProductFeatureCollectionRecord {
        id
        title
        productFeatures {
          title
          productFeatureImage {
            url
            alt
          }
          productFeatureVideo {
            url
            thumbnailUrl
          }
          productFeatureDescription
        }
      }
      ... on ProductSellingPointRecord {
        id
        title
        productSellingPointImage {
          url
          alt
        }
        productSellingPointList
      }
      ... on ProductAdditionalInformationCollectionRecord {
        id
        title
        productServiceTips {
          title
          productServiceTipImage {
            url
            alt
          }
          productServiceTipVideo {
            url
            thumbnailUrl
          }
          productServiceTipDescription
        }
      }
    }
  }
}

##also tried the below and it doesn't work either##

query MyQuery {
  productInformationArticle(filter: {id: {eq: "dlc6NRDhS1W-ZfKyAABcWg"}, _status: {eq: draft}}) {
    id
    title
    series
    important
    country
    _publishedAt
    productImage {
      url
      alt
    }
    content {
      ... on ProductTechnicalSpecificationRecord {
        title
        list
      }
      ... on ProductDescriptionRecord {
        id
        title
        productDescription
      }
      ... on ProductFeatureCollectionRecord {
        id
        title
        productFeatures {
          title
          productFeatureImage {
            url
            alt
          }
          productFeatureVideo {
            url
            thumbnailUrl
          }
          productFeatureDescription
        }
      }
      ... on ProductSellingPointRecord {
        id
        title
        productSellingPointImage {
          url
          alt
        }
        productSellingPointList
      }
      ... on ProductAdditionalInformationCollectionRecord {
        id
        title
        productServiceTips {
          title
          productServiceTipImage {
            url
            alt
          }
          productServiceTipVideo {
            url
            thumbnailUrl
          }
          productServiceTipDescription
        }
      }
    }
  }
}

Hello @jterry

For this you will have to include the “include drafts header” in your request like documented here: https://www.datocms.com/docs/content-delivery-api/api-endpoints#preview-mode-to-retrieve-draft-content

1 Like