fix(graphql): resolve QuantityValue unit to null when no unit is set - #1144
Conversation
`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
|
There was a problem hiding this comment.
Pull request overview
Corrects nullable GraphQL quantity units to return null when unset.
Changes:
- Returns
nullinstead 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.
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: 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 |



Changes in this pull request
QuantityValue::resolveUnit()returned an empty array when a quantity value had no unit. SinceQuantityValueUnitTypedefines no resolvers for its subfields (id,abbreviation,longname), graphql-php'sdefaultFieldResolverresolves each requested subfield of that array via$array[$key] ?? null— so an empty array made every subfield resolve tonullindividually instead of making the wholeunitfieldnull:{ "length": { "value": 8500, "unit": { "id": null } } }Returning
nullinstead makesunititselfnull, which is what the (nullable) field definition inQuantityValueTypeimplies:{ "length": { "value": 8500, "unit": null } }This affects both
QuantityValueandInputQuantityValue—InputQuantityValueType extends QuantityValueTypeand inherits theunitfield 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
unitsubfields unconditionally (e.g.data.length.unit.id) previously gotnulland now has to null-checkunitfirst. I added an entry todoc/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