File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -167,3 +167,40 @@ $db->table('users')
167
167
->column('name')->string(50)->graphqlField()
168
168
->logged()->right('CAN_SEE_NAME')->failWith(null);
169
169
```
170
+
171
+ ## Use your beans as input types
172
+
173
+ TDBM will automatically annotate the ` xxxDao::getById() ` method with a ` @Factory ` annotation.
174
+ As a result, you can directly inject you beans as arguments in your GraphQL queries.
175
+
176
+ For instance:
177
+
178
+ ``` php
179
+ class ProductController
180
+ {
181
+ // ...
182
+
183
+ /**
184
+ * @Query()
185
+ * @return Product[]
186
+ */
187
+ public function getProducts(Category $category): array
188
+ {
189
+ // ...
190
+ }
191
+ }
192
+ ```
193
+
194
+ Assuming "Category" is a bean, TDBM-GraphQL will automatically fetch the bean from the database and populate the ` $category `
195
+ argument with it.
196
+
197
+ Your GraphQL query will look like this:
198
+
199
+ ``` graphql
200
+ {
201
+ products (category : { id : 42 }) {
202
+ id
203
+ name
204
+ }
205
+ }
206
+ ```
Original file line number Diff line number Diff line change @@ -495,6 +495,7 @@ public function generatePhpCode(): ?FileGenerator
495
495
496
496
$ file = new FileGenerator ();
497
497
$ class = new ClassGenerator ();
498
+ $ class ->setAbstract (true );
498
499
$ file ->setClass ($ class );
499
500
$ file ->setNamespace ($ this ->generatedBeanNamespace );
500
501
@@ -651,6 +652,7 @@ public function generateDaoPhpCode(): ?FileGenerator
651
652
{
652
653
$ file = new FileGenerator ();
653
654
$ class = new ClassGenerator ();
655
+ $ class ->setAbstract (true );
654
656
$ file ->setClass ($ class );
655
657
$ file ->setNamespace ($ this ->generatedDaoNamespace );
656
658
Original file line number Diff line number Diff line change @@ -2008,6 +2008,18 @@ public function testTrait()
2008
2008
$ this ->assertTrue ($ refClass ->hasMethod ('findNothing ' ));
2009
2009
}
2010
2010
2011
+ /**
2012
+ * @depends testDaoGeneration
2013
+ */
2014
+ public function testNonInstantiableAbstractDaosAndBeans ()
2015
+ {
2016
+ $ refClass = new ReflectionClass (UserBaseDao::class);
2017
+ $ this ->assertFalse ($ refClass ->isInstantiable ());
2018
+
2019
+ $ refClass = new ReflectionClass (UserBaseBean::class);
2020
+ $ this ->assertFalse ($ refClass ->isInstantiable ());
2021
+ }
2022
+
2011
2023
/**
2012
2024
* @depends testDaoGeneration
2013
2025
*/
You can’t perform that action at this time.
0 commit comments