File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 88use TheCodingMachine \GraphQLite \Annotations \SourceField ;
99use TheCodingMachine \GraphQLite \Annotations \Type ;
1010use Symfony \Component \Security \Core \User \UserInterface ;
11+ use TheCodingMachine \GraphQLite \FieldNotFoundException ;
1112
1213/**
1314 * @Type(class=UserInterface::class)
14- * @SourceField(name="userName")
1515 */
1616class SymfonyUserInterfaceType
1717{
18+ /**
19+ * @Field
20+ */
21+ public function getUserName (UserInterface $ user ): string
22+ {
23+ // @phpstan-ignore-next-line Forward Compatibility for Symfony 5.3
24+ if (method_exists ($ user , 'getUserIdentifier ' )) {
25+ return $ user ->getUserIdentifier ();
26+ }
27+
28+ if (method_exists ($ user , 'getUserName ' )) {
29+ return $ user ->getUserName ();
30+ }
31+
32+ throw FieldNotFoundException::missingField (UserInterface::class, 'userName ' );
33+ }
34+
1835 /**
1936 * @Field()
2037 * @return string[]
You can’t perform that action at this time.
0 commit comments