Query by publishDate is not working

default discord avatar
last year
1 1


I want to have a simple scheduled publish feature like this


Repro Steps

  1. start server
git clone git@github.com:Stupidism/seo-mono.git
git checkout feng/test-scheduled-publish
pnpm I
nx run seo-payload:serve
  1. Create a doc and publish for the first time



  1. Query the doc with playground (to simulate guest access)
# Write your query or mutation here
query findTestDrafts {
    TestDrafts {
      docs {


  1. Update the doc with a publishDate after today:


  1. query the doc with playground again
    Now u can see the updated version instead of the former version:


Expected behavior

According to requirement and the description from the code snnipet, it should return the version that publishDate smaller than today.

  • discord user avatar
    Payload Team
    last year

    Hey @Stupidism,

    I'm glad to see you are exploring this solution more. Looking at the code for the access control, it is doing exactly what you're asking it to.
    The access control on TestDrafts for read first checks if a user is logged in before querying publishDate. Unless you have logged out it won't bother querying the way you are expecting.

    When you are querying in step 5, try from an incognito window or add a step to logout from the admin UI first.

    I was able to do this from your repro to be sure.

    If your app will have authenticated users and admin users for the panel either by role or using a separate auth collection, remember to add those conditions to your read access function as well to gate the content.

    2 replies
  • default discord avatar
    last year

    Aha, I get what you mean now.

    My understanding was wrong. I was expecting to see the Before version, when After version is not published

  • discord user avatar
    Payload Team
    last year

    Ah! Sure, you could still have that but you'll need to modify the query to use an or operator to allow the before to come through under the different conditions.

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.