Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed Jun 8, 2018
2 parents eb4bb0c + 9109b9d commit 9ad0d11
Show file tree
Hide file tree
Showing 44 changed files with 2,041 additions and 302 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Expand Up @@ -17,16 +17,14 @@ matrix:
- php: 7.2
env: PHP_CS_FIXER=true
- php: 7.2
env: SYMFONY_VERSION=3.4.*
env: SYMFONY_VERSION=3.4.* GRAPHQLPHP_VERSION=^0.11.2
- php: 7.2
env: SYMFONY_VERSION=4.0.* TEST_COVERAGE=true
- php: 7.2
env: SYMFONY_VERSION=4.1.* DEPENDENCIES=dev
env: SYMFONY_VERSION=4.1.* STABILITY=beta
- php: nightly
env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs
allow_failures:
- php: 7.2
env: SYMFONY_VERSION=4.1.* DEPENDENCIES=dev
- php: nightly
env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs

Expand All @@ -37,15 +35,17 @@ cache:
- vendor/

before_install:
- if [ ${DEPENDENCIES} = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
- if [ "${STABILITY}" != "" ]; then perl -pi -e 's/^}$/,"minimum-stability":"'"${STABILITY}"'"}/' composer.json; fi;
- if [ "${SYMFONY_VERSION}" != "" ]; then perl -pi -e 's#"(symfony/.*)":\s*".*"#"$1":"'"${SYMFONY_VERSION}"'"#' composer.json; fi;
- if [ "${PHPUNIT_VERSION}" != "" ]; then composer req "phpunit/phpunit:${PHPUNIT_VERSION}" --dev --no-update; fi;
- if [ ${TEST_COVERAGE} != true ]; then phpenv config-rm xdebug.ini || true; fi
- composer selfupdate
- if [ $SYMFONY_VERSION ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --dev --no-update; fi;
- if [ $GRAPHQLPHP_VERSION ]; then composer require "webonyx/graphql-php:${GRAPHQLPHP_VERSION}" --dev --no-update; fi;

install: composer update --prefer-source --no-interaction --optimize-autoloader ${COMPOSER_UPDATE_FLAGS}

script:
- composer validate --no-check-lock --strict
- bin/phpunit --debug $( if [ $TEST_COVERAGE = true ]; then echo "-d xdebug.max_nesting_level=1000 --coverage-clover=build/logs/clover.xml"; fi; )
- if [ ${PHP_CS_FIXER} = true ]; then composer require --dev 'friendsofphp/php-cs-fixer:^2.0' && bin/php-cs-fixer fix --diff --dry-run -v; fi;

Expand Down
6 changes: 6 additions & 0 deletions CacheWarmer/CompileCacheWarmer.php
Expand Up @@ -28,6 +28,12 @@ public function isOptional()
*/
public function warmUp($cacheDir)
{
// use warm up cache dir if type generator cache dir not already explicitly declare
$baseCacheDir = $this->typeGenerator->getBaseCacheDir();
if (null === $this->typeGenerator->getCacheDir(false)) {
$this->typeGenerator->setBaseCacheDir($cacheDir);
}
$this->typeGenerator->compile(TypeGenerator::MODE_WRITE | TypeGenerator::MODE_OVERRIDE);
$this->typeGenerator->setBaseCacheDir($baseCacheDir);
}
}
10 changes: 9 additions & 1 deletion Command/GraphQLDumpSchemaCommand.php
Expand Up @@ -60,6 +60,12 @@ protected function configure()
InputOption::VALUE_NONE,
'Enabled classic json format: { "__schema": {...} }.'
)
->addOption(
'with-descriptions',
null,
InputOption::VALUE_NONE,
'Dump schema including descriptions.'
)
;
}

Expand All @@ -74,13 +80,15 @@ private function createFile(InputInterface $input)
{
$format = strtolower($input->getOption('format'));
$schemaName = $input->getOption('schema');
$includeDescription = $input->getOption('with-descriptions');

$file = $input->getOption('file') ?: $this->baseExportPath.sprintf('/../var/schema%s.%s', $schemaName ? '.'.$schemaName : '', $format);

switch ($format) {
case 'json':
$request = [
'query' => Introspection::getIntrospectionQuery(false),
// TODO(mcg-web): remove silence deprecation notices after removing webonyx/graphql-php <= 0.11
'query' => @Introspection::getIntrospectionQuery($includeDescription),
'variables' => [],
'operationName' => null,
];
Expand Down
3 changes: 3 additions & 0 deletions Config/Parser/GraphQLParser.php
Expand Up @@ -294,6 +294,9 @@ private function astValueNodeToConfig(ValueNode $valueNode)

private function cleanAstDescription($description)
{
if (property_exists($description, 'value')) {
$description = $description->value;
}
$description = trim($description);

return empty($description) ? null : $description;
Expand Down
6 changes: 3 additions & 3 deletions Config/Processor/InheritanceProcessor.php
Expand Up @@ -121,7 +121,7 @@ private static function checkTypeExists($name, array $configs, $child)
{
if (!isset($configs[$name])) {
throw new \InvalidArgumentException(sprintf(
'Type %s inherits by %s not found.',
'Type %s inherited by %s not found.',
json_encode($name),
json_encode($child)
));
Expand All @@ -142,9 +142,9 @@ private static function checkAllowedInheritsTypes($name, array $config, array $a
{
if (empty($config['decorator']) && isset($config['type']) && !in_array($config['type'], $allowedTypes)) {
throw new \InvalidArgumentException(sprintf(
'Type %s can\'t inherits %s because %s is not allowed type (%s).',
json_encode($name),
'Type %s can\'t inherit %s because its type (%s) is not allowed type (%s).',
json_encode($child),
json_encode($name),
json_encode($config['type']),
json_encode($allowedTypes)
));
Expand Down
2 changes: 1 addition & 1 deletion Definition/Type/CustomScalarType.php
Expand Up @@ -35,7 +35,7 @@ public function parseValue($value)
/**
* {@inheritdoc}
*/
public function parseLiteral(/* GraphQL\Language\AST\ValueNode */ $valueNode)
public function parseLiteral(/* GraphQL\Language\AST\ValueNode */ $valueNode, array $variables = null)
{
return $this->call('parseLiteral', $valueNode);
}
Expand Down
6 changes: 2 additions & 4 deletions DependencyInjection/Configuration.php
Expand Up @@ -111,7 +111,7 @@ private function definitionsSection()
->children()
->variableNode('default_resolver')->defaultValue([Resolver::class, 'defaultResolveFn'])->end()
->scalarNode('class_namespace')->defaultValue('Overblog\\GraphQLBundle\\__DEFINITIONS__')->end()
->scalarNode('cache_dir')->defaultValue($this->cacheDir.'/overblog/graphql-bundle/__definitions__')->end()
->scalarNode('cache_dir')->defaultNull()->end()
->booleanNode('use_classloader_listener')->defaultTrue()->end()
->booleanNode('auto_compile')->defaultTrue()->end()
->booleanNode('show_debug_info')->info('Show some performance stats in extensions')->defaultFalse()->end()
Expand Down Expand Up @@ -149,9 +149,7 @@ private function servicesSection()
->scalarNode('expression_language')
->defaultValue(self::NAME.'.expression_language.default')
->end()
->scalarNode('cache_expression_language_parser')
->defaultValue(self::NAME.'.cache_expression_language_parser.default')
->end()
->scalarNode('cache_expression_language_parser')->end()
->end()
->end();

Expand Down
12 changes: 0 additions & 12 deletions DependencyInjection/OverblogGraphQLExtension.php
Expand Up @@ -13,17 +13,14 @@
use Overblog\GraphQLBundle\EventListener\DebugListener;
use Overblog\GraphQLBundle\EventListener\ErrorHandlerListener;
use Overblog\GraphQLBundle\EventListener\ErrorLoggerListener;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ExpressionLanguage\ParserCache\ArrayParserCache;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;

class OverblogGraphQLExtension extends Extension implements PrependExtensionInterface
{
Expand All @@ -33,7 +30,6 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->treatConfigs($configs, $container);

$this->setBatchingMethod($config, $container);
$this->setExpressionLanguageDefaultParser($container);
$this->setServicesAliases($config, $container);
$this->setSchemaBuilderArguments($config, $container);
$this->setSchemaArguments($config, $container);
Expand Down Expand Up @@ -124,14 +120,6 @@ private function setBatchingMethod(array $config, ContainerBuilder $container)
$container->setParameter($this->getAlias().'.batching_method', $config['batching_method']);
}

private function setExpressionLanguageDefaultParser(ContainerBuilder $container)
{
$class = version_compare(Kernel::VERSION, '3.2.0', '>=') ? ArrayAdapter::class : ArrayParserCache::class;
$definition = new Definition($class);
$definition->setPublic(false);
$container->setDefinition($this->getAlias().'.cache_expression_language_parser.default', $definition);
}

private function setDebugListener(array $config, ContainerBuilder $container)
{
if ($config['definitions']['show_debug_info']) {
Expand Down
35 changes: 24 additions & 11 deletions DependencyInjection/OverblogGraphQLTypesExtension.php
Expand Up @@ -41,44 +41,57 @@ class OverblogGraphQLTypesExtension extends Extension

public function load(array $configs, ContainerBuilder $container)
{
$this->checkTypesDuplication($configs);
// flatten config is a requirement to support inheritance
$flattenConfig = [call_user_func_array('array_merge', $configs)];
$configuration = $this->getConfiguration($flattenConfig, $container);
$config = $this->processConfiguration($configuration, $flattenConfig);
$configs = array_filter($configs);
//$configs = array_filter($configs);
if (count($configs) > 1) {
throw new \InvalidArgumentException('Configs type should never contain more than one config to deal with inheritance.');
}
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter($this->getAlias().'.config', $config);
}

public function containerPrependExtensionConfig(array $config, ContainerBuilder $container)
public function containerPrependExtensionConfig(array $configs, ContainerBuilder $container)
{
$typesMappings = $this->mappingConfig($config, $container);
$typesMappings = $this->mappingConfig($configs, $container);
// reset treated files
$this->treatedFiles = [];
$typesMappings = call_user_func_array('array_merge', $typesMappings);
$typeConfigs = [];
// treats mappings
foreach ($typesMappings as $params) {
$this->prependExtensionConfigFromFiles($params['type'], $params['files'], $container);
$typeConfigs = array_merge($typeConfigs, $this->parseTypeConfigFiles($params['type'], $params['files'], $container));
}

$this->checkTypesDuplication($typeConfigs);
// flatten config is a requirement to support inheritance
$flattenTypeConfig = call_user_func_array('array_merge', $typeConfigs);

$container->prependExtensionConfig($this->getAlias(), $flattenTypeConfig);
}

/**
* @param $type
* @param SplFileInfo[] $files
* @param ContainerBuilder $container
*
* @return array
*/
private function prependExtensionConfigFromFiles($type, $files, ContainerBuilder $container)
private function parseTypeConfigFiles($type, $files, ContainerBuilder $container)
{
$config = [];
foreach ($files as $file) {
$fileRealPath = $file->getRealPath();
if (isset($this->treatedFiles[$fileRealPath])) {
continue;
}

$typeConfig = call_user_func(self::PARSERS[$type].'::parse', $file, $container);
$container->prependExtensionConfig($this->getAlias(), $typeConfig);
$config[] = call_user_func(self::PARSERS[$type].'::parse', $file, $container);
$this->treatedFiles[$file->getRealPath()] = true;
}

return $config;
}

private function checkTypesDuplication(array $typeConfigs)
Expand Down
38 changes: 32 additions & 6 deletions Generator/TypeGenerator.php
Expand Up @@ -23,6 +23,8 @@ class TypeGenerator extends BaseTypeGenerator

private $useClassMap;

private $baseCacheDir;

private static $classMapLoaded = false;

public function __construct(
Expand All @@ -31,25 +33,49 @@ public function __construct(
$cacheDir,
array $configs,
$useClassMap = true,
callable $configProcessor = null)
{
callable $configProcessor = null,
$baseCacheDir = null
) {
$this->setCacheDir($cacheDir);
$this->configProcessor = null === $configProcessor ? static::DEFAULT_CONFIG_PROCESSOR : $configProcessor;
$this->configs = $configs;
$this->useClassMap = $useClassMap;
$this->baseCacheDir = $baseCacheDir;

parent::__construct($classNamespace, $skeletonDirs);
}

/**
* @return string
* @return string|null
*/
public function getBaseCacheDir()
{
return $this->baseCacheDir;
}

/**
* @param string|null $baseCacheDir
*/
public function setBaseCacheDir($baseCacheDir)
{
$this->baseCacheDir = $baseCacheDir;
}

/**
* @return string|null
*/
public function getCacheDir()
public function getCacheDir(/*bool $useDefault = true*/)
{
return $this->cacheDir;
$useDefault = func_num_args() > 0 ? func_get_arg(0) : true;
if ($useDefault) {
return $this->cacheDir ?: $this->baseCacheDir.'/overblog/graphql-bundle/__definitions__';
} else {
return $this->cacheDir;
}
}

/**
* @param string $cacheDir
* @param string|null $cacheDir
*
* @return $this
*/
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -66,6 +66,7 @@ Documentation
- [Promise](Resources/doc/data-fetching/promise.md)
- [Security](Resources/doc/security/index.md)
- [Handle CORS](Resources/doc/security/handle-cors.md)
- [Object access control](Resources/doc/security/object-access-control.md)
- [Fields access control](Resources/doc/security/fields-access-control.md)
- [Fields public control](Resources/doc/security/fields-public-control.md)
- [Limiting query depth](Resources/doc/security/limiting-query-depth.md)
Expand All @@ -76,6 +77,8 @@ Documentation
Talks and slides to help you start
----------------------------------

* GraphQL in Symfony *by Bernd Alter* - [Twitter](https://twitter.com/bazoo0815)
- [Talk about GraphQL and its implementation with Symfony (26.04.2017)](https://www.slideshare.net/berndalter7/graphql-in-symfony) `English`
* GraphQL is right in front of us, let's to it! *by Renato Mendes Figueiredo* - [Twitter](https://twitter.com/renatomefi), [GitHub](https://github.com/renatomefi)
- [Slides at http://talks.mefi.in/graphql-scotphp17](http://talks.mefi.in/graphql-scotphp17/) `English`
- [Video at SymfonyCamp UA 2017](https://www.youtube.com/watch?v=jyoYlnCPNgk) `English`
Expand Down
8 changes: 4 additions & 4 deletions Resources/config/routing/graphql.yml
@@ -1,23 +1,23 @@
overblog_graphql_endpoint:
path: /
defaults:
_controller: overblog_graphql.controller.graphql:endpointAction
_controller: Overblog\GraphQLBundle\Controller\GraphController::endpointAction
_format: "json"

overblog_graphql_batch_endpoint:
path: /batch
defaults:
_controller: overblog_graphql.controller.graphql:batchEndpointAction
_controller: Overblog\GraphQLBundle\Controller\GraphController::batchEndpointAction
_format: "json"

overblog_graphql_multiple_endpoint:
path: /graphql/{schemaName}
defaults:
_controller: overblog_graphql.controller.graphql:endpointAction
_controller: Overblog\GraphQLBundle\Controller\GraphController::endpointAction
_format: "json"

overblog_graphql_batch_multiple_endpoint:
path: /graphql/{schemaName}/batch
defaults:
_controller: overblog_graphql.controller.graphql:batchEndpointAction
_controller: Overblog\GraphQLBundle\Controller\GraphController::batchEndpointAction
_format: "json"
8 changes: 7 additions & 1 deletion Resources/config/services.yml
Expand Up @@ -75,7 +75,7 @@ services:
class: Overblog\GraphQLBundle\ExpressionLanguage\ExpressionLanguage
public: false
arguments:
- '@overblog_graphql.cache_expression_language_parser'
- '@?overblog_graphql.cache_expression_language_parser'

overblog_graphql.cache_compiler:
class: Overblog\GraphQLBundle\Generator\TypeGenerator
Expand All @@ -86,6 +86,8 @@ services:
- "%overblog_graphql.cache_dir%"
- "%overblog_graphql_types.config%"
- "%overblog_graphql.use_classloader_listener%"
- ~
- "%kernel.cache_dir%"
calls:
- ['addUseStatement', ['Overblog\GraphQLBundle\Definition\ConfigProcessor']]
- ['addUseStatement', ['Overblog\GraphQLBundle\Definition\LazyConfig']]
Expand Down Expand Up @@ -119,6 +121,10 @@ services:
- "@overblog_graphql.request_parser"
- "%overblog_graphql.handle_cors%"
- "%overblog_graphql.batching_method%"

Overblog\GraphQLBundle\Controller\GraphController:
public: true
alias: 'overblog_graphql.controller.graphql'

overblog_graphql.command.dump_schema:
class: Overblog\GraphQLBundle\Command\GraphQLDumpSchemaCommand
Expand Down

0 comments on commit 9ad0d11

Please sign in to comment.