nuwave / nuwave/lighthouse

Type based on Laravel model ignores regular php properties

Open
#2,687 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the shown Laravel model property and GraphQL type, then trace the model field resolution path that currently returns null. Confirm the existing getter and @rename workaround behavior before changing the lookup. Done means a regular public PHP property resolves its value and the behavior has a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, laravel, php
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.