Skip to content

Commit 688d81e

Browse files
authored
Merge pull request #138 from moufmouf/mysql8
Base DAOs and beans should be abstract
2 parents 4573dd7 + 15a6f14 commit 688d81e

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

doc/graphqlite.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,40 @@ $db->table('users')
167167
->column('name')->string(50)->graphqlField()
168168
->logged()->right('CAN_SEE_NAME')->failWith(null);
169169
```
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+
```

src/Utils/BeanDescriptor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ public function generatePhpCode(): ?FileGenerator
495495

496496
$file = new FileGenerator();
497497
$class = new ClassGenerator();
498+
$class->setAbstract(true);
498499
$file->setClass($class);
499500
$file->setNamespace($this->generatedBeanNamespace);
500501

@@ -651,6 +652,7 @@ public function generateDaoPhpCode(): ?FileGenerator
651652
{
652653
$file = new FileGenerator();
653654
$class = new ClassGenerator();
655+
$class->setAbstract(true);
654656
$file->setClass($class);
655657
$file->setNamespace($this->generatedDaoNamespace);
656658

tests/TDBMDaoGeneratorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,18 @@ public function testTrait()
20082008
$this->assertTrue($refClass->hasMethod('findNothing'));
20092009
}
20102010

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+
20112023
/**
20122024
* @depends testDaoGeneration
20132025
*/

0 commit comments

Comments
 (0)