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
8 changes: 0 additions & 8 deletions Resolver/AbstractResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ private function loadSolution($name)
$loader = $this->solutions[$name];
$this->solutions[$name] = $loader();
$this->fullyLoadedSolutions[$name] = true;
$this->postLoadSolution($this->solutions[$name]);

return $this->solutions[$name];
}
Expand All @@ -95,13 +94,6 @@ private function loadSolutions()
return $this->solutions;
}

/**
* @param mixed $solution
*/
protected function postLoadSolution($solution)
{
}

/**
* @param mixed $solution
*
Expand Down
10 changes: 0 additions & 10 deletions Resolver/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ private static function createTypeLoadingException($alias, $errorOrException)
);
}

protected function postLoadSolution($solution)
{
// also add solution with real type name if needed for typeLoader when using autoMapping
if ($solution && !$this->hasSolution($solution->name)) {
$this->addSolution($solution->name, function () use ($solution) {
return $solution;
}, [], ['id' => get_class($solution), 'alias' => $solution->name]);
}
}

protected function supportedSolutionClass()
{
return Type::class;
Expand Down
7 changes: 0 additions & 7 deletions Resources/doc/definitions/resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,13 @@ Resolvers can be define 2 different ways

```yaml
services:
_instanceof:
GraphQL\Type\Definition\Type:
tags: ['overblog_graphql.type']

App\Mutation\:
resource: '../src/Mutation'
tags: ['overblog_graphql.mutation']

App\Resolver\:
resource: '../src/Resolver'
tags: ['overblog_graphql.resolver']

App\Type\:
resource: '../src/Type'
```

**Note:**
Expand Down
50 changes: 47 additions & 3 deletions Resources/doc/definitions/type-system/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,33 @@ Types can be define 3 different ways:
You can also declare PHP types (any subclass of `GraphQL\Type\Definition\Type`)
in `src/*Bundle/GraphQL` or `app/GraphQL`
they will be auto discover (thanks to auto mapping). Auto map classes are accessible by FQCN
(example: `AppBunble\GraphQL\Type\DateTimeType`), you can also alias type adding
a public static function `getAliases`
(example: `AppBunble\GraphQL\Type\DateTimeType`), you can also alias a type by
implementing `Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface`
that returns an array of aliases.

here an example:

```php
<?php

namespace App\GraphQL\Type;

use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
use GraphQL\Type\Definition\ScalarType;

class DateTimeType extends ScalarType implements AliasedInterface
{
/**
* {@inheritdoc}
*/
public static function getAliases()
{
return ['DateTime', 'Date'];
}
// ...
}
```

You can also define custom dirs using config:
```yaml
overblog_graphql:
Expand All @@ -53,13 +77,33 @@ Types can be define 3 different ways:
- "%kernel.root_dir%/src/*Bundle/CustomDir"
- "%kernel.root_dir%/src/AppBundle/{foo,bar}"
```
To disable auto mapping:

If using Symfony 3.3+ disabling auto mapping can be a solution to leave place to native
DI `autoconfigure`:

```yaml
overblog_graphql:
definitions:
auto_mapping: false
```

Here an example of how this can be done with DI `autoconfigure`:

```yaml
services:
_instanceof:
GraphQL\Type\Definition\Type:
tags: ['overblog_graphql.type']

App\Type\:
resource: '../src/Type'
```

**Note:**
* Types are lazy loaded so when using Symfony DI `autoconfigure` or this bundle auto mapping, the
only access to type is FQCN (or aliases if implements the aliases interface).
* When using FQCN in yaml definition, backslash must be correctly quotes,

3. **The service way**

Creating a service tagged `overblog_graphql.type`
Expand Down
11 changes: 10 additions & 1 deletion Tests/Functional/App/GraphQL/HelloWord/Type/MutationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
use Overblog\GraphQLBundle\Resolver\MutationResolver;

final class MutationType extends ObjectType
final class MutationType extends ObjectType implements AliasedInterface
{
public function __construct(MutationResolver $mutator)
{
Expand All @@ -29,4 +30,12 @@ public function __construct(MutationResolver $mutator)
],
]);
}

/**
* {@inheritdoc}
*/
public static function getAliases()
{
return ['Calc'];
}
}
11 changes: 10 additions & 1 deletion Tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
use Overblog\GraphQLBundle\Resolver\ResolverResolver;
use Overblog\GraphQLBundle\Tests\Functional\App\IsolatedResolver\EchoResolver;

final class QueryType extends ObjectType
final class QueryType extends ObjectType implements AliasedInterface
{
public function __construct(ResolverResolver $resolver)
{
Expand All @@ -29,4 +30,12 @@ public function __construct(ResolverResolver $resolver)
],
]);
}

/**
* {@inheritdoc}
*/
public static function getAliases()
{
return ['Query'];
}
}
51 changes: 50 additions & 1 deletion UPGRADE-0.11.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ UPGRADE FROM 0.10 to 0.11
- [Errors handler](#errors-handler)
- [Promise adapter interface](#promise-adapter-interface)
- [Expression language](#expression-language)
- [Type autoMapping and Symfony DI autoconfigure](#type-automapping-and-symfony-di-autoconfigure)

### GraphiQL

Expand Down Expand Up @@ -49,7 +50,6 @@ UPGRADE FROM 0.10 to 0.11
* Made errors handler more customizable

Upgrading:
- User
- Delete configuration to override base user exception classes.
```diff
overblog_graphql:
Expand Down Expand Up @@ -129,3 +129,52 @@ UPGRADE FROM 0.10 to 0.11
- resolve: '@=resolver('foo', [request])'
+ resolve: '@=resolver('foo', [serv('request_stack')])'
```
### Type autoMapping and Symfony DI `autoconfigure`

When using these functionality, type will be accessible only by FQCN in schema definition,
(if class not implementing `Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface`).
So if you want to use the `true` type name don't forget to declare it as an alias using interface.
This change is for a performance mater types are lazy loaded.

example:

```php
<?php

namespace App\GraphQL\Type;

use GraphQL\Type\Definition\ScalarType;

class DateTimeType extends ScalarType
{
public $name = 'DateTme';
// ...
}
```
**Before 0.11**: DateTimeType could be accessed by FQCN `App\GraphQL\Type\DateTimeType` and the real `DateTimeType`.
**Since 0.11**: Only FQCN `App\GraphQL\Type\DateTimeType` is accessible

here how this can be done in 0.11:

```php
<?php

namespace App\GraphQL\Type;

use GraphQL\Type\Definition\ScalarType;
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;

class DateTimeType extends ScalarType implements AliasedInterface
{
public $name = 'DateTme';

/**
* {@inheritdoc}
*/
public static function getAliases()
{
return ['DateTime'];
}
// ...
}
```