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 8
8
use TheCodingMachine \GraphQLite \Annotations \SourceField ;
9
9
use TheCodingMachine \GraphQLite \Annotations \Type ;
10
10
use Symfony \Component \Security \Core \User \UserInterface ;
11
+ use TheCodingMachine \GraphQLite \FieldNotFoundException ;
11
12
12
13
/**
13
14
* @Type(class=UserInterface::class)
14
- * @SourceField(name="userName")
15
15
*/
16
16
class SymfonyUserInterfaceType
17
17
{
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
+
18
35
/**
19
36
* @Field()
20
37
* @return string[]
You can’t perform that action at this time.
0 commit comments