payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.94k stars 1.59k forks source link

Draft parameter isn't accepted by or cascaded into the rich text field #6643

Open evelynhathaway opened 5 months ago

evelynhathaway commented 5 months ago

Link to reproduction

No response

Describe the Bug

Links that are relationships inside a rich text field links do not return drafts if the parent query has the draft parameter. The specific rich text field doesn't provide a draft parameter to GraphQL either.

The result is that all rich text relationship links will always return the published version (or the first draft if no published version exists).

This solves unexpected behavior like broken rich text relationship links in our frontend if the linked document location changed since the linked document was last published (or since the first draft if no published version exists).

Similar functionality was added to first class relationship fields as part of: #4985

To Reproduce

  1. Create a collection with drafts, a slug field, and a rich text field
  2. Create two documents in the collection with unique slugs, then publish them
  3. For one of the documents (let's call it document A), change the slug and save as a draft
  4. In the rich text field for document B, link to document A using the internal link type
  5. Save draft and preview document B
  6. Note that the link to document A on document B points to the slug of the published version, which isn't found in draft mode

Payload Version

v2.16.1

Adapters and Plugins

Slate Editor, MongoDB

AlessioGr commented 4 months ago

Hey @evelynhathaway I'm not able to reproduce this issue. In draft mode, doc b links to doc a with slug a2 and in non-draft mode, doc b links to doc a with slug a. a2 coming from the draft version, and a coming from the published version. So this works as expected:

https://github.com/payloadcms/payload/assets/70709113/51c06e9f-67b1-415a-ba56-1f6d8bd0a242

I did test this on payload v2.21.0 and @payloadcms/richtext-slate 1.5.2. Could you upgrade to these versions and see if that fixes it for you? If it does not, could you provide me with a repository which reproduces this, optimally with a small int test?