Skip to content

fix(graphql): resolve QuantityValue unit to null when no unit is set - #1144

Merged
kingjia90 merged 2 commits into
2026.2from
issue-324-quantityvalue-unit-null
Aug 19, 2026
Merged

fix(graphql): resolve QuantityValue unit to null when no unit is set#1144
kingjia90 merged 2 commits into
2026.2from
issue-324-quantityvalue-unit-null

Conversation

@kingjia90

Copy link
Copy Markdown
Contributor

Changes in this pull request

QuantityValue::resolveUnit() returned an empty array when a quantity value had no unit. Since QuantityValueUnitType defines no resolvers for its subfields (id, abbreviation, longname), graphql-php's defaultFieldResolver resolves each requested subfield of that array via $array[$key] ?? null — so an empty array made every subfield resolve to null individually instead of making the whole unit field null:

{ "length": { "value": 8500, "unit": { "id": null } } }

Returning null instead makes unit itself null, which is what the (nullable) field definition in QuantityValueType implies:

{ "length": { "value": 8500, "unit": null } }

This affects both QuantityValue and InputQuantityValueInputQuantityValueType extends QuantityValueType and inherits the unit field and its resolver unchanged.

Also adds a regression test (tests/GraphQL/Resolver/QuantityValueTest.php) covering the no-unit case for both types, non-quantity-value input, and the unit-is-set case so the array shape stays intact.

Heads-up for reviewers

This changes the response shape for consumers. A client accessing unit subfields unconditionally (e.g. data.length.unit.id) previously got null and now has to null-check unit first. I added an entry to doc/01_Installation_and_Upgrade/01_Upgrade_Notes.md — the version heading is a guess based on the latest tag (v2026.2.5), please adjust it if this lands in a different release.

Additional info

Verified locally (PHP 8.4): the new tests fail against the current code with Failed asserting that Array &0 [] is null (3 of 4) and pass with the fix; PHPStan and php-cs-fixer are clean on the changed files.

Fixes pimcore/platform-version#324

`QuantityValue::resolveUnit()` returned an empty array when the quantity
value had no unit. Since `QuantityValueUnitType` relies on graphql-php's
default field resolver, every requested subfield of that empty array was
resolved to `null` individually, so the response contained
`unit: {id: null}` instead of `unit: null`.

Returning `null` makes the whole `unit` field null, as the (nullable)
schema definition implies. Affects both `QuantityValue` and
`InputQuantityValue`, which inherits the field unchanged.

Fixes pimcore/platform-version#324
Copilot AI balanced review requested due to automatic review settings August 19, 2026 10:31
@kingjia90 kingjia90 added this to the 2026.2.6 milestone Aug 19, 2026
@kingjia90 kingjia90 self-assigned this Aug 19, 2026
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Corrects nullable GraphQL quantity units to return null when unset.

Changes:

  • Returns null instead of an empty array for missing units.
  • Adds resolver regression tests.
  • Documents the response-shape change for 2026.2.6.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/GraphQL/Resolver/QuantityValue.php Corrects missing-unit resolution.
tests/GraphQL/Resolver/QuantityValueTest.php Covers resolver behavior and unit data.
doc/01_Installation_and_Upgrade/01_Upgrade_Notes.md Documents client migration requirements.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Install dependencies with Composer

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

@kingjia90
kingjia90 merged commit 2c7ea81 into 2026.2 Aug 19, 2026
17 of 19 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 19, 2026
@kingjia90
kingjia90 deleted the issue-324-quantityvalue-unit-null branch August 19, 2026 13:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants