GraphQL API and published/draft status

I am working on a Gatsby site, and trying to introduce what I thought would be a fairly basic filter. It currently looks something like this…

  {
    allContentfulArticle(
      filter: {
        sys: {
          revision: {
            ne: null
          }
        }
      }
    )  {
      edges {
        node {
          id
          title {
            title
          }
          slug
        }
      }
    }
  }

What I really want that filter to look for is Draft content. This statement filters correctly if a post has never been published, but if it is published and returned to Draft, revisions is no longer null.

I’m kind of getting the impression that the answer is “no you can’t do this,” so I’m mostly interested in why. This seems like very basic functionality. Or am I totally dumb and missing something?

1 Like

Sorry I can’t give you the answer but we also really want to see this functionality. In addition to this we want to get validation errors for all changed/drafted entities.
Thanks

Does anyone from Contentful have any input on this?

This really does seem silly, it seems like the only API that contains relevant metadata to determine this is the Content Management API. With Gatsby, I suppose you could also query the Delivery API, maybe in an onCreateNode, and if you get a 404 then set a draft: true on that node…

Another option could be to use a “status” boolean field where false would mean it’s a Draft and true means it’s Published, then use a UI extension that doesn’t render an input (maybe just text), but sets up an event listener to set the status

const sysChanged = sdk.entry.onSysChanged(sys => {
  if (!sys.publishedVersion) {
    sdk.field.setValue(false);
  } else {
    sdk.field.setValue(true);
  }
});
1 Like

Did you ever find a solution to this issue? I’m also running into the problem of published posts that have been reverted to Draft. Is there any way to filter for those in the API now?