Skip to content

Commit

Permalink
Merge branch 'annotations' of github.com:overblog/GraphQLBundle into …
Browse files Browse the repository at this point in the history
…annotations
  • Loading branch information
Vincz committed Dec 20, 2018
2 parents 772058b + 92917ba commit 098693e
Show file tree
Hide file tree
Showing 37 changed files with 346 additions and 123 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ cache:
directories:
- $HOME/.composer/cache
- $HOME/.php_cs.cache
- vendor/

before_install:
- if [ "${STABILITY}" != "" ]; then perl -pi -e 's/^}$/,"minimum-stability":"'"${STABILITY}"'"}/' composer.json; fi;
Expand All @@ -37,7 +36,9 @@ jobs:
- php: 7.2
env: SYMFONY_VERSION=4.0.*
- php: 7.2
env: SYMFONY_VERSION=4.1.* STABILITY=beta
env: SYMFONY_VERSION=4.1.*
- php: 7.3
env: SYMFONY_VERSION=4.2.*
- php: nightly
env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs

Expand Down
36 changes: 36 additions & 0 deletions docs/definitions/expression-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,42 @@ All definition config entries can use expression language but it must be explici

[For more details on expression syntax](http://symfony.com/doc/current/components/expression_language/syntax.html)

Private services
----------------

It is not possible to use private services with `service` or `serv` functions since this is equivalent to call
`get` method on the container. Private services must be tag as global variable to be accessible.

Yaml example:

```yaml
App\MyPrivateService:
public: false
tags:
- { name: overblog_graphql.global_variable, alias: my_private_service }
```
To use a vendor private services:
```php
<?php

$vendorPrivateServiceDef = $container->findDefinition(\Vendor\PrivateService::class);
$vendorPrivateServiceDef->addTag('overblog_graphql.global_variable', ['alias' => 'vendor_private_service']);
```

Usage:

```yaml
MyType:
type: object
config:
fields:
name:
type: String!
resolve: '@=my_private_service.formatName(value)'
```
Custom expression function
--------------------------
Expand Down
40 changes: 17 additions & 23 deletions docs/events/index.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
Events
=========

[Events](http://symfony.com/doc/master/event_dispatcher.html) are a way to hook
into the execution flow. This bundle provides various events from executor
and context value initialization, executor result formatting (data, errors, extensions),
errors/warnings formatting.

With this in mind we now turn to explain each one of them.
[Events](http://symfony.com/doc/master/event_dispatcher.html) are a way to hook into the execution flow. This bundle provides various events around the executor's context value initialization and result formatting (data, errors, extensions).

Executor context value
----------------------

*Event:* `graphql.executor.context`

This event can be listen to initialize executor `contextValue` argument.
It is used to initialize the executor's `contextValue` argument.


Executor initialisation
-----------------------

*Event:* `graphql.pre_executor`

This event can be listen to initialize executor execute arguments
(`schema`, `requestString`, `rootValue`, `contextValue`, `variableValue`, `operationName`).
Used to initialize the executor's execute arguments: `schema`, `requestString`, `rootValue`, `contextValue`, `variableValue`, `operationName`.

For example:
Example:

* Initializing `rootValue` with the current user (we assume that user is fully authenticated)
* Initialize the `rootValue` with the current user (we assume that user is fully authenticated)

```yaml
App\EventListener\RootValueInitialization:
Expand Down Expand Up @@ -62,12 +56,12 @@ Executor result

*Event:* `graphql.post_executor`

This event can be listen to set custom error handling and formatting, it can also be use to
add information to `extensions` section.
Used to set custom error handling and formatting. It can also be used to
add information to the `extensions` section.

For example:
Example:

* How to add `credits` entry in `extensions` section
* Add a `credits` entry in the `extensions` section

```yaml
App\EventListener\Credits:
Expand Down Expand Up @@ -106,11 +100,11 @@ Error formatting

*Event:* `graphql.error_formatting`

This event can be listen to add or remove fields from result `errors` and `extensions.warnings`
sections, it can also be use to log errors or exception. Each single error or warning will trigger
Used to add or remove fields from the result's `errors` and `extensions.warnings`
sections. It can also be used to log errors or exception. Each single error or warning will trigger
an event.

For example:
Example:

* How to add error code:

Expand Down Expand Up @@ -158,17 +152,17 @@ For example:
```

*Note:*
- This event is dispatch by this bundle default error handler, that the reason why, disabling
error handler will also disable this event.
- This event is dispatched by this bundle's default error handler. Disabling it
will also disable this event.

Type loaded
----------------

*Event:* `graphql.type_loaded`

This event can be listen to modified type before schema registration.
Used to modify types before schema registration.

For example:
Example:

```yaml
App\EventListener\TypeDecorator:
Expand All @@ -188,7 +182,7 @@ class TypeDecorator
public function onTypeLoaded(TypeLoadedEvent $event)
{
$type = $event->getType();
// here we can modified type
// modify the type
}
}
```
2 changes: 1 addition & 1 deletion docs/security/fields-public-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ You can also use `config.fieldsDefaultPublic` to handle the setting globally on
```yaml
AnObject:
type: object
fieldsDefaultPublic: "@=service('my_service').isGranted(typeName, fieldName)"
config:
fieldsDefaultPublic: "@=service('my_service').isGranted(typeName, fieldName)"
fields:
id:
type: "String!"
Expand Down
5 changes: 1 addition & 4 deletions src/Config/CustomScalarTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

namespace Overblog\GraphQLBundle\Config;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class CustomScalarTypeDefinition extends TypeDefinition
{
public function getDefinition()
{
$builder = new TreeBuilder();
$node = $builder->root('_custom_scalar_config');
$node = self::createNode('_custom_scalar_config');

$node
->children()
Expand Down
5 changes: 1 addition & 4 deletions src/Config/EnumTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

namespace Overblog\GraphQLBundle\Config;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class EnumTypeDefinition extends TypeDefinition
{
public function getDefinition()
{
$builder = new TreeBuilder();
$node = $builder->root('_enum_config');
$node = self::createNode('_enum_config');

$node
->children()
Expand Down
5 changes: 1 addition & 4 deletions src/Config/InputObjectTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

namespace Overblog\GraphQLBundle\Config;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class InputObjectTypeDefinition extends TypeDefinition
{
public function getDefinition()
{
$builder = new TreeBuilder();
$node = $builder->root('_input_object_config');
$node = self::createNode('_input_object_config');

$node
->children()
Expand Down
5 changes: 1 addition & 4 deletions src/Config/InterfaceTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

namespace Overblog\GraphQLBundle\Config;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class InterfaceTypeDefinition extends TypeWithOutputFieldsDefinition
{
public function getDefinition()
{
$builder = new TreeBuilder();
$node = $builder->root('_interface_config');
$node = self::createNode('_interface_config');

$node
->children()
Expand Down
4 changes: 1 addition & 3 deletions src/Config/ObjectTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
namespace Overblog\GraphQLBundle\Config;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class ObjectTypeDefinition extends TypeWithOutputFieldsDefinition
{
public function getDefinition()
{
$builder = new TreeBuilder();
$node = $builder->root('_object_config');
$node = self::createNode('_object_config');

$node
->children()
Expand Down
32 changes: 20 additions & 12 deletions src/Config/TypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Overblog\GraphQLBundle\Config;

use Overblog\GraphQLBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

abstract class TypeDefinition
Expand All @@ -24,16 +25,14 @@ public static function create()

protected function resolveTypeSection()
{
$builder = new TreeBuilder();
$node = $builder->root('resolveType', 'variable');
$node = self::createNode('resolveType', 'variable');

return $node;
}

protected function nameSection()
{
$builder = new TreeBuilder();
$node = $builder->root('name', 'scalar');
$node = self::createNode('name', 'scalar');
$node->isRequired();
$node->validate()
->ifTrue(function ($name) {
Expand All @@ -47,24 +46,21 @@ protected function nameSection()

protected function defaultValueSection()
{
$builder = new TreeBuilder();
$node = $builder->root('defaultValue', 'variable');
$node = self::createNode('defaultValue', 'variable');

return $node;
}

protected function descriptionSection()
{
$builder = new TreeBuilder();
$node = $builder->root('description', 'scalar');
$node = self::createNode('description', 'scalar');

return $node;
}

protected function deprecationReasonSelection()
{
$builder = new TreeBuilder();
$node = $builder->root('deprecationReason', 'scalar');
$node = self::createNode('deprecationReason', 'scalar');

$node->info('Text describing why this field is deprecated. When not empty - field will not be returned by introspection queries (unless forced)');

Expand All @@ -73,8 +69,7 @@ protected function deprecationReasonSelection()

protected function typeSelection($isRequired = false)
{
$builder = new TreeBuilder();
$node = $builder->root('type', 'scalar');
$node = self::createNode('type', 'scalar');

$node->info('One of internal or custom types.');

Expand All @@ -84,4 +79,17 @@ protected function typeSelection($isRequired = false)

return $node;
}

/**
* @internal
*
* @param string $name
* @param string $type
*
* @return \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
*/
protected static function createNode(string $name, string $type = 'array')
{
return Configuration::getRootNodeWithoutDeprecation(new TreeBuilder($name, $type), $name, $type);
}
}
4 changes: 1 addition & 3 deletions src/Config/TypeWithOutputFieldsDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Overblog\GraphQLBundle\Config;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

abstract class TypeWithOutputFieldsDefinition extends TypeDefinition
{
Expand All @@ -16,8 +15,7 @@ abstract class TypeWithOutputFieldsDefinition extends TypeDefinition
*/
protected function outputFieldsSelection(string $name = 'fields')
{
$builder = new TreeBuilder();
$node = $builder->root($name);
$node = self::createNode($name);
$node
->isRequired()
->requiresAtLeastOneElement();
Expand Down
5 changes: 1 addition & 4 deletions src/Config/UnionTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

namespace Overblog\GraphQLBundle\Config;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class UnionTypeDefinition extends TypeDefinition
{
public function getDefinition()
{
$builder = new TreeBuilder();
$node = $builder->root('_union_config');
$node = self::createNode('_union_config');

$node
->children()
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/GlobalVariablesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function process(ContainerBuilder $container): void
$expressionLanguageDefinition->addMethodCall(
'addGlobalName',
[
\sprintf('globalVariables->get(\'%s\')', $attributes['alias']),
\sprintf('globalVariable->get(\'%s\')', $attributes['alias']),
$attributes['alias'],
]
);
Expand Down
Loading

0 comments on commit 098693e

Please sign in to comment.