File tree Expand file tree Collapse file tree 3 files changed +45
-3
lines changed
src/Infrastructure/Api/Http/GraphQL Expand file tree Collapse file tree 3 files changed +45
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Jerowork \ExampleApplicationGraphqlAttributeSchema \Infrastructure \Api \Http \GraphQL \Resolver \Query ;
6+
7+ use Jerowork \ExampleApplicationGraphqlAttributeSchema \Domain \Blog \BlogRepository ;
8+ use Jerowork \ExampleApplicationGraphqlAttributeSchema \Infrastructure \Api \Http \GraphQL \Type \BlogType ;
9+ use Jerowork \ExampleApplicationGraphqlAttributeSchema \Infrastructure \Api \Http \GraphQL \Type \ContentType ;
10+ use Jerowork \GraphqlAttributeSchema \Attribute \Query ;
11+ use Symfony \Component \DependencyInjection \Attribute \Autoconfigure ;
12+
13+ #[Autoconfigure(public: true )]
14+ final readonly class ContentQuery
15+ {
16+ public function __construct (
17+ private BlogRepository $ blogRepository ,
18+ ) {}
19+
20+ #[Query]
21+ public function content (string $ id ): ContentType
22+ {
23+ // Other types can be added here, e.g. a page type
24+ $ blog = $ this ->blogRepository ->getById ($ id );
25+
26+ return new BlogType ($ blog );
27+ }
28+ }
Original file line number Diff line number Diff line change 66
77use DateTimeImmutable ;
88use Jerowork \ExampleApplicationGraphqlAttributeSchema \Domain \Blog \Blog ;
9- use Jerowork \ExampleApplicationGraphqlAttributeSchema \Infrastructure \Api \Http \GraphQL \Loader \AuthorTypeLoader ;
109use Jerowork \GraphqlAttributeSchema \Attribute \Cursor ;
1110use Jerowork \GraphqlAttributeSchema \Attribute \Field ;
1211use Jerowork \GraphqlAttributeSchema \Attribute \Option \ListType ;
1615
1716#[Exclude]
1817#[Type]
19- final readonly class BlogType
18+ final readonly class BlogType implements ContentType
2019{
2120 public function __construct (
2221 public Blog $ blog ,
@@ -41,7 +40,6 @@ public function getTitle(): string
4140 return $ this ->blog ->title ;
4241 }
4342
44- #[Field(type: AuthorType::class, deferredTypeLoader: AuthorTypeLoader::class)]
4543 public function getAuthor (): string
4644 {
4745 return $ this ->blog ->authorId ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Jerowork \ExampleApplicationGraphqlAttributeSchema \Infrastructure \Api \Http \GraphQL \Type ;
6+
7+ use Jerowork \ExampleApplicationGraphqlAttributeSchema \Infrastructure \Api \Http \GraphQL \Loader \AuthorTypeLoader ;
8+ use Jerowork \GraphqlAttributeSchema \Attribute \Field ;
9+ use Jerowork \GraphqlAttributeSchema \Attribute \InterfaceType ;
10+
11+ #[InterfaceType]
12+ interface ContentType
13+ {
14+ #[Field(type: AuthorType::class, deferredTypeLoader: AuthorTypeLoader::class)]
15+ public function getAuthor (): string ;
16+ }
You can’t perform that action at this time.
0 commit comments