Skip to content

fix: resolve product variation type when the node is a base Post model#1020

Merged
kidunot89 merged 4 commits into
wp-graphql:developfrom
kidunot89:feat/variation-type-post-fallback
Jun 30, 2026
Merged

fix: resolve product variation type when the node is a base Post model#1020
kidunot89 merged 4 commits into
wp-graphql:developfrom
kidunot89:feat/variation-type-post-fallback

Conversation

@kidunot89

Copy link
Copy Markdown
Collaborator

Summary

Post_Types::resolve_product_variation_type() assumes $value is a Product_Variation model and calls $value->get_type(). When a variation node is loaded through the generic post loader instead — e.g. a cart item's variation.node on a site running Polylang, which doesn't manage the product_variation post-type — $value arrives as a base \WPGraphQL\Model\Post with no get_type(), and the resolver fatals (surfacing downstream as "Callback returned incorrect type; expected Promise").

This adds a fallback: when get_type() isn't callable, resolve the variation's product type from its ID via wc_get_product(). The error message also reports the resolved $product_type instead of the now-possibly-absent $value->type.

Also removes a stray graphql_debug() left in the ProductWithPricing price resolver.

Test plan

  • Query a cart whose items have variations on a Polylang-enabled store (cart.contents.nodes[].variation.node) — previously fataled, now resolves the correct ProductVariation type.
  • Query a variation through the normal Product_Variation model path — unchanged (still uses get_type()).
  • Query a variation of an unsupported product type — still throws the "not supported" UserError (now with the resolved type name).

A cart item's variation node can be loaded through the generic post loader (e.g. under Polylang, which doesn't manage the product_variation post-type), arriving as a base \WPGraphQL\Model\Post that has no get_type(). resolve_product_variation_type() then fatals. Fall back to resolving the variation's product type from its ID via wc_get_product() when get_type() isn't callable.
@coveralls

coveralls commented Jun 27, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28297639419

Coverage increased (+0.001%) to 91.801%

Details

  • Coverage increased (+0.001%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (6 of 7 lines covered, 85.71%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
includes/class-post-types.php 7 6 85.71%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 20186
Covered Lines: 18531
Line Coverage: 91.8%
Coverage Strength: 153.15 hits per line

💛 - Coveralls

@kidunot89 kidunot89 merged commit e3cf944 into wp-graphql:develop Jun 30, 2026
23 checks passed
@kidunot89 kidunot89 deleted the feat/variation-type-post-fallback branch June 30, 2026 14:03
@kidunot89 kidunot89 added the bugfix Implements bugfix label Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Implements bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants