Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying parent info in preview mode returns the current post info. #3001

Closed
1 of 3 tasks
jeremyProwseYS opened this issue Dec 11, 2023 · 3 comments
Closed
1 of 3 tasks
Labels
Duplicate This issue or pull request already exists

Comments

@jeremyProwseYS
Copy link

Description

On querying a posts parent info outside of preview mode everything works as expected. However when "asPreview" is passed into the query, or when the preview connection is used in the query the returned parent info equates to the current post.

For example if you have a postId of '2' that is a child of postId '1', when querying the parent of '2' outside of preview mode it returns what would be expected: '1'. When using preview mode and the same query object for postId '2' the parent id returned is now '2'.

I presume this is to do with previews / revisions and their relationship to the post they spawn from, specifically what is being set in terms of the parent information when a preview is requested.

Please see attached screenshots for the current behaviour.

using-asPreview-param
using-preview-connection

Steps to reproduce

If given the above example of page '2' being a child of page '1', the below query should return '1' when targeting page.parent.id. Currently it returns the id of the original version of the previewed page.

query MyPageQuery {
  page(id: 2, idType: DATABASE_ID, asPreview: true) {
    databaseId
    title
    parent {
      node {
        ... on Page {
          databaseId
          title
        }
      }
    }
  }
}

Additional context

No response

WPGraphQL Version

1.19.0

WordPress Version

6.4.2

PHP Version

8.2.10

Additional environment details

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have disabled ALL plugins except for WPGraphQL.

  • Yes
  • My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.
@justlevine
Copy link
Collaborator

Hey @jeremyProwseYS ,

What you're describing is intentional behavior (due to how post revisions are stored, like you mentioned), and is documented as such in the description for the asPreview arg (which is sadly not the most discoverable).

You can find the active discussion around this behavior and a workaround in #2876 .

(Closing as duplicate).

@justlevine justlevine added the Duplicate This issue or pull request already exists label Dec 11, 2023
@justlevine justlevine closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2023
@jeremyProwseYS
Copy link
Author

jeremyProwseYS commented Dec 11, 2023

@justlevine Thanks for your reply, I had already figured a work-around using the revisionOf prop to traverse the true parent structure for the post. However this is just that, a "workaround" and I was wondering if there were any plans to reintroduce expected behaviour for the parent prop when preview is concerned. Surely the previewOf prop suggested by Jason in the linked post #2876 would make more sense to house the info currently returned in the parent prop? I'm just not sure changing the return value / behaviour of a prop based on a variable, such as preview, makes logical sense.

@justlevine
Copy link
Collaborator

Surely the previewOf prop suggested by Jason in the linked post #2876 would make more sense to house the info currently returned in the parent prop

Exactly. Please share any feedback you might have on #2876 so we can keep the discussion all in one place 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate This issue or pull request already exists
Projects
Status: Done
Development

No branches or pull requests

2 participants