Skip to content

Fix generated type for nullable custom scalars#36

Merged
ruudk merged 3 commits intoruudk:mainfrom
11k:fix/nullable-custom-scalar-union-test
Mar 1, 2026
Merged

Fix generated type for nullable custom scalars#36
ruudk merged 3 commits intoruudk:mainfrom
11k:fix/nullable-custom-scalar-union-test

Conversation

@11k
Copy link
Copy Markdown
Contributor

@11k 11k commented Mar 1, 2026

Nullable shorthand (?Type) is only valid for a single type. When no mapping is defined for a custom scalar, it resolves to multiple native scalar types, so nullable output must be represented as an explicit union that includes null.

Schema

type Video {
  createdAt: Time
}

Before

final class Video
{
    // Syntax error
    public ?int|string|float|bool $createdAt {
        get => $this->createdAt ??= $this->data['createdAt'] !== null ? $this->data['createdAt'] : null;
    }

    // ...
}

After

final class Video
{
    public null|int|string|float|bool $createdAt {
        get => $this->createdAt ??= $this->data['createdAt'] !== null ? $this->data['createdAt'] : null;
    }

    // ...
}

11k added 3 commits February 28, 2026 15:38
The test captures invalid `?` shorthand generation for nullable custom scalars that expand to multi-type unions, ensuring we require explicit `null|...` syntax.
Use explicit `null|...` syntax for nullable custom scalars that expand to multi-type unions so generated PHP types remain valid.
Copy link
Copy Markdown
Owner

@ruudk ruudk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, thanks!

Keep them coming!

@ruudk ruudk merged commit dc502b5 into ruudk:main Mar 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants