Allow Path fields to be optional (#8) - #11
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.UnresolvablePathExceptioninstead of a fatalError("Call to a member function get() on null").QueryResolverrecognizes the new internalUnresolvedValuesentinel and skips adding that key to the output array.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.