Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->append([__DIR__ . '/castor.php'])
->exclude(['cache', 'Bundle/Resources/config'])
->notName('FooTransformerStaticCallable.php')
->exclude(['cache', 'Resources/stubs'])
;

return (new PhpCsFixer\Config())
Expand Down
134 changes: 134 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,140 @@ Install using Composer:
```bash
composer require hecht-a/graphql-orm
```

## Configuration
Configure the GraphQL endpoint and entity mapping.

Example :
```yaml
graphql_orm:
endpoint: 'http://localhost:4000'
max_depth: 3

mapping:
entity:
dir: '%kernel.project_dir%/src/GraphQL/Entity'
namespace: App\GraphQL\Entity
repository:
dir: '%kernel.project_dir%/src/GraphQL/Repository'
namespace: App\GraphQL\Repository
```
Options:

- `endpoint` : GraphQL API endpoint.
- `max_depth` : Maximum nested relation loading depth.
- `mapping.entity` : Entity generation directory and namespace.
- `mapping.repository` : Repository generation directory and namespace.

---

## Entity Generator
GraphqlOrm provides a console wizard to generate entities and repositories.

Create a new entity :

```bash
php bin/console graphqlorm:make:entity Task
````

The command generates :
- Entity class
- Repository class
- Identifier property
- Scalar properties
- Relations

The generator asks interactively :
- GraphQL root name
- Identifier field
- Scalar properties
- Relations

Example wizard :
```
Add a property ? yes

Property name:
id

Field name in GraphQL schema :
id

Identifier ? yes

Type:
int

Nullable ? no

Add a property ? yes

Property name:
title

Field name in GraphQL schema :
title

Type:
string

Nullable ? no

Add a property ? yes

Property name:
user

Field name in GraphQL schema :
user

Type:
relation
```

Relation wizard :
```
Target entity :
> Us<TAB>
User

Relation type :
object
```
Existing entities are automatically suggested using autocomplete.

Generated example :
```php
#[GraphqlEntity('tasks', TaskRepository::class)]
class Task
{
#[GraphqlField(mappedFrom: 'id', identifier: true)]
private int $id;

#[GraphqlField(mappedFrom: 'title')]
private string $title;

#[GraphqlField(mappedFrom: 'user')]
private ?User $user = null;
}
```
Repository :
```php
/**
* @extends GraphqlEntityRepository<Task>
* @method Task[] findAll()
* @method Task[] findBy(array $criteria)
*/
class TaskRepository extends GraphqlEntityRepository
{
public function __construct(GraphqlManager $graphQLManager)
{
parent::__construct($graphQLManager, Task::class);
}
}
```
---

## Quick Start
### Define an Entity
```php
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
"symfony/stopwatch": "^7.4",
"symfony/http-kernel": "^7.4",
"symfony/config": "^7.4",
"symfony/http-client": "^7.4"
"symfony/http-client": "^7.4",
"symfony/console": "^7.4",
"symfony/filesystem": "^7.4",
"symfony/finder": "^7.4"
},
"require-dev": {
"symfony/phpunit-bridge": "^8.0",
Expand Down
Loading