wp-graphql / wpgraphql-acf

Re-architecture of WPGraphQL for ACF
GNU General Public License v3.0
91 stars 12 forks source link

fix: image fields (and other connection fields) not properly resolving when queried `asPreview` #189

Closed jasonbahl closed 8 months ago

jasonbahl commented 8 months ago

What does this implement/fix? Explain your changes.

This fixes a bug where Image fields (and other fields that return Connections) were not properly resolving when querying a page asPreview: true.

In order to support preview resolution, all field names and keys are tracked and then during resolution filters are applied to ensure the meta is resolved properly for each field (either the published post or the preview post).

Fields that return Connection types were not properly being tracked in this registry, leading to the preview resolver filter not being applied for these fields, so they would return preview data from the published node instead of the preview node.

Does this close any currently open issues?

closes #187

Any other comments?

I published a page with the following image uploaded for the image fields:

When I query the page with asPreview: false I see the image returned as expected:

CleanShot 2024-03-13 at 16 39 29

When I query the page as an authenticated user with asPreview: true, I see the published image value (expected, since I have not made any un-published changes yet):

CleanShot 2024-03-13 at 16 41 08

Now, if I go replace the image:

And query asPreview: true again:

BEFORE

I still see the published image, not the preview image. 😭

CleanShot 2024-03-13 at 16 44 37

AFTER

I see the image that was added to the preview but not yet published! 🥳

CleanShot 2024-03-13 at 16 43 43

coveralls commented 8 months ago

Pull Request Test Coverage Report for Build 046b302be979fdbff9d14a546b3ee38b1f51ab2b-PR-189

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Files with Coverage Reduction New Missed Lines %
src/FieldConfig.php 1 91.84%
<!-- Total: 1 -->
Totals Coverage Status
Change from base Build ece620b9f911b507d9cc9754d75449bf2879bc0e: 0.3%
Covered Lines: 2093
Relevant Lines: 3285

💛 - Coveralls