Skip to content

The featuredImage doesn't take the asPreview parameter into account. #2664

Description

@idflood

Description

We are using the asPreview parameter on our project to enable users to preview changes they make to posts and pages.

While the query itself is mostly correct, the featured image does not take the asPreview attribute into account and always displays the last published value instead of the draft one.

Steps to reproduce

  1. Create a post, set a featured image and publish it
  2. Edit the post, change title and featured image
  3. Click the "Preview" button
  4. In the GraphiQL IDE paste the sample query below.

The result has the updated title but the featured image (databaseID and src) are incorrect.

Additional context

Sample query

{
  post(id: 116, idType: DATABASE_ID, asPreview: true) {
    title
    featuredImageDatabaseId
    featuredImage {
      node {
        id
        databaseId
        medium: sourceUrl(size: LARGE)
      }
    }
  }
}

Result

"post": {
      "title": "Etiam imperdiet imperdiet orci?",
      "featuredImageDatabaseId": 73,
      "featuredImage": {
        "node": {
          "id": "cG9zdDo3Mw==",
          "databaseId": 73,
          "medium": "http://local.test/wp-content/uploads/2022/11/alexander-shatov-PHH_0uw9-Qw-unsplash-scaled.jpg"
        }
      }
    }

Expected

"post": {
      "title": "Etiam imperdiet imperdiet orci?",
      "featuredImageDatabaseId": 81,
      "featuredImage": {
        "node": {
          "id": "cG9zdDo4MQ==",
          "databaseId": 81,
          "medium": "http://local.test/wp-content/uploads/2022/11/mike-meyers-haAxbjiHds-unsplash-scaled.jpg"
        }
      }
    }

WPGraphQL Version

1.13.6

WordPress Version

6.1.1

PHP Version

8.0

Additional enviornment 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: connectionsRelating to GraphQL Connectionseffort: lowAround a day or lessimpact: medMinor performance improvements, fix broad user base issuesstatus: actionableReady for work to begintype: bugIssue that causes incorrect or unexpected behavior

    Type

    No fields configured for Bug.

    Projects

    Status
    💬 In Discussion

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions