Skip to content

Allow Path fields to be optional (#8) - #11

Merged
1blankz7 merged 1 commit into
masterfrom
fix/php-object-query-8-optional-fields
Aug 21, 2026
Merged

Allow Path fields to be optional (#8)#11
1blankz7 merged 1 commit into
masterfrom
fix/php-object-query-8-optional-fields

Conversation

@1blankz7

Copy link
Copy Markdown
Collaborator

Summary

  • Path::optional() marks a field as allowed to fail resolution. If any step in the chain is unresolvable, the resolver now omits that key from the result set instead of throwing — matching the "not present in the result set" behavior requested in Allow fields to be not present in the result set #8.
  • Non-optional paths that fail to resolve an intermediate property now throw a clean, catchable UnresolvablePathException instead of a fatal Error ("Call to a member function get() on null").
  • QueryResolver recognizes the new internal UnresolvedValue sentinel and skips adding that key to the output array.
  • README updated with an "Optional fields" section and example.

Closes #8

Test plan

  • composer tests:all (phpunit, 13/13 passing incl. 2 new tests)
  • composer lint:code (phpcs PSR12, clean)
  • composer lint:phpstan (level 8, no errors)

Ran via a PHP 8.1-compatible composer/phpunit/phpstan/phpcs toolchain in Docker since PHP isn't available locally in this sandbox.

Fields that cannot be resolved (missing intermediate/leaf properties)
previously either threw an uncatchable fatal Error (chained gets on a
missing intermediate property) or silently returned null. Neither
behavior let callers distinguish "field is genuinely null" from
"field could not be resolved at all".

- Path::optional() marks a path as allowed to fail; on failure the
  resolver now omits the key from the result set instead of throwing.
- Non-optional paths now throw a clean, catchable
  UnresolvablePathException instead of a fatal Error when an
  intermediate step is missing.
- QueryResolver recognizes the internal UnresolvedValue sentinel and
  skips adding that key to the result.

Closes #8
@1blankz7
1blankz7 merged commit 4695651 into master Aug 21, 2026
1 check passed
@1blankz7
1blankz7 deleted the fix/php-object-query-8-optional-fields branch August 21, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow fields to be not present in the result set

1 participant