cms icon indicating copy to clipboard operation
cms copied to clipboard

GraphQL Live Preview: New entries without saving are not returned

Open carola-kolossal opened this issue 3 years ago • 16 comments

Bug description

Cant't use Live Preview as expected see https://statamic.dev/live-preview#headless-frontend-frameworks. Only saved entries are returned by GraphQL. New Entries without saving are missing.

How to reproduce

  1. Open Statamic CMS
  2. Create new entry without saving it
  3. Open 'Live Preview'
  4. Pass corresponding token as parameter to GraphQL and try to retrieve new entry via GraphQL

Result: Entry is not returned by GraphQL

  1. Save entry Result: Entry is returned by GraphQL

Logs

No response

Versions

3.3.7

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

No response

Additional details

No response

carola-kolossal avatar Jun 01 '22 10:06 carola-kolossal

I'm having the same issue it only returns values when I save and published, not when I save as a draft, @carola-kolossal do you have solved something about this ?

luigif-gp avatar Jun 27 '22 15:06 luigif-gp

image

luigif-gp avatar Jun 27 '22 20:06 luigif-gp

@luigifgp This issue is about a brand new entry, e.g. one that is still in progress on the "create" form. It hasn't been saved yet. Has yours been saved?

jasonvarga avatar Jun 27 '22 20:06 jasonvarga

@jasonvarga yes i'm saving it as a draft but the problem persists the only way i get value is by posting it but i guess that shouldn't be a good idea if i haven't finished my post and my frontend syncs with a broken post

luigif-gp avatar Jun 27 '22 20:06 luigif-gp

We are using "normal" live preview and getting the same thing

edalzell avatar Jun 27 '22 22:06 edalzell

I have the same issue.

  • New unsaved entries returns nothing
  • ~~Entries in draft returns nothing~~
  • Published entries works like expected

danielbrodin avatar Jul 05 '22 10:07 danielbrodin

I'm having the same issue it only returns values when I save and published, not when I save as a draft, @carola-kolossal do you have solved something about this ?

@luigifgp The issue only exist if an entry is new and not saved. Unpublished and saved entries are returned by GraphQL as expected. Set the filter to filter: {status: "draft"} or if you like to get both use regex filter: {status: {regex: "(draft|published)"}}. If nothing is set only 'published' entries are returned.

Screenshot 2022-07-05 at 13 16 38

carola-kolossal avatar Jul 05 '22 11:07 carola-kolossal

While filtering for (draft|published) works, including drafts in live-preview should be the default behaviour.

el-schneider avatar Jul 13 '22 08:07 el-schneider

Hello,

This github issue is the closest thing I could find that would describe the problem I'm having.

Basically, I have a Next.JS frontend headlessly connected to Statamic CMS via GraphQL.

The live preview function is connected properly and it works when editing already created entries.

The problem arises on the create entry page, where the live preview button is available but the post has not yet been saved nor published.

There is no slug to which the live preview can point to in this case, because it has not yet been saved inside entries for graphQL to read, therefore the content I enter inside the entry has no way to show in the live preview.

What I'm wondering is if this is a feature that is not implemented yet or am I missing something here?

Thank you for your time!

sc-urs avatar Oct 20 '22 12:10 sc-urs

This github issue is the closest thing I could find that would describe the problem I'm having.

It's literally the same problem. You've come to the right place!

jasonvarga avatar Oct 20 '22 14:10 jasonvarga

I also have the same problem trying to access the not yet saved entry in PHP as recommended in the docs: https://statamic.dev/live-preview#custom-rendering

jakubjo avatar Oct 27 '22 06:10 jakubjo

any updates on this one?

CptCompiler avatar Dec 19 '22 14:12 CptCompiler

I tried using the filter: {status: "draft"} option but this is returning a Forbidden: status error. This includes sending with the token query parameter. Is there another thing which needs to be configured to be able to see these entries?

Smef avatar Jul 05 '23 16:07 Smef

I tried using the filter: {status: "draft"} option but this is returning a Forbidden: status error.

Filters are disabled by default. You need to opt into it. https://statamic.dev/graphql#filtering

jasonvarga avatar Jul 05 '23 17:07 jasonvarga

Ah, yes. I had that enabled for the REST API, but not GraphQL. Thanks!

This does allow it to be queried, but unfortunately it also exposes drafts to the public, which isn't great.

Smef avatar Jul 05 '23 17:07 Smef