Query by publishDate is not working

default discord avatar
Stupidism
last year
1 1

Background

I want to have a simple scheduled publish feature like this

#567

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

http://localhost:3333/admin/collections/test-drafts/62be8d54722f5bd46633ca9f

image

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

image

  1. Update the doc with a publishDate after today:

image

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

image

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
    DanRibbens
    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.
    image

    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
    Stupidism
    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
    DanRibbens
    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!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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