Skip to content

Navigation Menu

Sign in
Sign up

Reference types by their FQCNs #1161

mathroc started this conversation in Ideas
Feb 8, 2024 · 1 comments · 1 reply
Discussion options

Hi,

Just something that could make it easier to spot issues (with tools such as Psalm for example) and help with refactoring, there are attributes that take GraphQL type names, it would be nice to also be able to reference the type by their FQCN, e.g.:

#[GQL\Type]
final class User
{
 public function __construct(
 #[GQL\Field(type: 'ID!')]
 public readonly string $id,
 ) {}
}
#[GQL\Provider]
final class UserExtension
{
 #[GQL\Query(
 target User::class, // instead of targetType: 'User'
 )]
 public function one(): int
 {
 return 1;
 }
}
You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Hi again @mathroc!
We cannot do that because we are targeting a GraphQL Type while you would like to target a PHP Class.
When working with annotations / attributes, we have this mapping (ie. 1 GraphQL Type = 1 PHP Class) so it would work.
But it would not with other mapping technics (like yaml which is still widely used).
Still, in this context, I guess we could allow both, detect if the target contains \ and try to guess the associated type using the ClassesTypesMap.

You must be logged in to vote
1 reply
Comment options

Still, in this context, I guess we could allow both, detect if the target contains \ and try to guess the associated type using the ClassesTypesMap.

yes could be that or a separate argument for FQCNs. And, obviously, it would only work for type that comes from a PHP class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /