Type based on Laravel model ignores regular php properties
Describe the bug
class Test extends Model
{
public string $test = 'test';
}
type Test {
test: String
}
This will always return null for test, it never reads the property.
Expected behavior/Solution
It should read the property value.
We are moving away from Laravel get___Attribute getters (which work) as the native php 8.4 virtual property syntax has much better IDE integration and static analysis, so this is a bug that could lead to easily missed mistakes. I guess the implementation uses Laravel array access to retrieve the values, which is imo fine, but it should fall back to trying regular php object properties in case that fails.
Note: A current workaround is using @rename to 'rename' the attribute to itself.
Lighthouse Version
6.57.1
You may define your own default field resolver. See https://lighthouse-php.com/master/digging-deeper/extending-lighthouse.html#changing-the-default-resolver https://github.com/nuwave/lighthouse/issues/2191
Sure, but I think it's kinda unexpected the default one just ignores regular php properties.
Can you add a pull request with a failing test case?
I thought about changing the default field resolver for a while to work better with models. It sometimes does unnecessary work by calling isset first, because Laravel magic properties are actually resolved twice then.
Can you add a pull request with a failing test case?
I'll take a look tomorrow