Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If an object implements \ArrayAccess, check both array value and property #1531

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shish
Copy link

@shish shish commented Feb 25, 2024

I have an object which has known properties accessible via properties, and some extra bits added at runtime accessible via \ArrayAccess syntax. graphql-php sees the \ArrayAccess and now it thinks that all my fields are null :(

My specific use-case is that I had a class like

#[Type]
class Post {
    #[Field]
    public string $title = "Untitled";
}

and everything was working fine, but then I turned it into

#[Type]
class Post implements ArrayAccess {
    #[Field]
    public string $title = "Untitled";

    // ...
    // implementing ArrayAccess methods for internal use
    // only and not exposing them to graphql at all
    // ...
}

and suddenly any query which referred to the "title" field started throwing Cannot return null for non-nullable field "Post.title"

src/Utils/Utils.php Outdated Show resolved Hide resolved
@spawnia
Copy link
Collaborator

spawnia commented Feb 26, 2024

Please extend testDefaultResolverGrabsValuesOffOfCommonPhpDataStructures.

src/Utils/Utils.php Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants