graphql-php icon indicating copy to clipboard operation
graphql-php copied to clipboard

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

Open shish opened this issue 1 year ago • 1 comments

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"

shish avatar Feb 25 '24 16:02 shish

Please extend testDefaultResolverGrabsValuesOffOfCommonPhpDataStructures.

spawnia avatar Feb 26 '24 10:02 spawnia