If an object implements \ArrayAccess, check both array value and property#1531
If an object implements \ArrayAccess, check both array value and property#1531shish wants to merge 2 commits into
Conversation
|
Please extend |
67585eb to
f2a1729
Compare
spawnia
left a comment
There was a problem hiding this comment.
I plan to include this when I start working on the next major version.
|
Hey, tried to update this branch against master and ran into an issue: your fork (shish/graphql-php) seems to be archived, so it's read-only now, even for you. I already resolved the merge conflict against master locally, so once you unarchive the fork (or open a fresh PR from an active one), updating it should be quick. |
|
Unarchived now, thank you for keeping it updated :) |
# Conflicts: # tests/Executor/ExecutorTest.php
There was a problem hiding this comment.
Pull request overview
This PR adjusts the default field resolution behavior so that objects implementing \ArrayAccess are no longer treated as array-only containers: if the requested key is not available via ArrayAccess, graphql-php will now fall back to reading an object property of the same name. This aligns ArrayAccess-implementing objects with typical PHP usage where they can expose both real properties and dynamic “extra” values.
Changes:
- Update
Utils::extractKey()to check object properties when a\ArrayAccesslookup does not yield a value. - Extend the executor resolver test to cover an
\ArrayAccessobject with a real property (setProperty) and ensure it resolves correctly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/Executor/ExecutorTest.php | Adds coverage proving the default resolver can read a real property from an ArrayAccess object. |
| src/Utils/Utils.php | Updates key extraction to fall back to property access for ArrayAccess objects. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I have an object which has known properties accessible via properties, and some extra bits added at runtime accessible via
\ArrayAccesssyntax. graphql-php sees the\ArrayAccessand now it thinks that all my fields are null :(My specific use-case is that I had a class like
and everything was working fine, but then I turned it into
and suddenly any query which referred to the "title" field started throwing
Cannot return null for non-nullable field "Post.title"