Skip to content

Commit 0949844

Browse files
committed
Initial commit
0 parents  commit 0949844

16 files changed

+501
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor/
2+
/composer.lock
3+
/build
4+
/var
5+
/cache

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:30:"PHPUnit\Runner\TestResultCache":224:{a:2:{s:7:"defects";a:1:{s:76:"TheCodingMachine\Tdbm\Graphql\Bundle\Tests\FunctionalTest::testServiceWiring";i:5;}s:5:"times";a:1:{s:76:"TheCodingMachine\Tdbm\Graphql\Bundle\Tests\FunctionalTest::testServiceWiring";d:4.224;}}}

.travis.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
language: php
2+
sudo: false
3+
cache:
4+
directories:
5+
- $HOME/.composer/cache/files
6+
#- $HOME/symfony-bridge/.phpunit
7+
8+
env:
9+
global:
10+
- PHPUNIT_FLAGS="-v"
11+
#- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
12+
13+
matrix:
14+
fast_finish: true
15+
include:
16+
# Test the latest stable release
17+
- php: 7.1
18+
- php: 7.2
19+
- php: 7.3
20+
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"
21+
22+
# Test LTS versions.
23+
- php: 7.3
24+
env: DEPENDENCIES="symfony/lts:^4"
25+
26+
# Latest commit to master
27+
- php: 7.3
28+
env: STABILITY="dev"
29+
30+
allow_failures:
31+
# Minimum supported dependencies with the latest and oldest PHP version
32+
- php: 7.3
33+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
34+
- php: 7.1
35+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
36+
# Dev-master is allowed to fail.
37+
- env: STABILITY="dev"
38+
39+
before_install:
40+
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
41+
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
42+
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
43+
44+
install:
45+
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
46+
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
47+
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
48+
#- ./vendor/bin/simple-phpunit install
49+
50+
script:
51+
- composer validate --strict --no-check-lock
52+
# simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and
53+
# it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge)
54+
#- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
55+
- composer phpstan
56+
- ./vendor/bin/phpunit
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\Tdbm\Graphql\Bundle\DependencyInjection;
5+
6+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7+
use Symfony\Component\Config\Definition\ConfigurationInterface;
8+
9+
class Configuration implements ConfigurationInterface
10+
{
11+
public function getConfigTreeBuilder()
12+
{
13+
$treeBuilder = new TreeBuilder();
14+
$rootNode = $treeBuilder->root('tdbm-graphql');
15+
16+
$rootNode
17+
->children()
18+
->scalarNode('type_namespace')->defaultValue('App\\Types')->end()
19+
->scalarNode('generated_type_namespace')->defaultValue(null)->end()
20+
->end()
21+
;
22+
23+
return $treeBuilder;
24+
}
25+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\Tdbm\Graphql\Bundle\DependencyInjection;
5+
6+
use function class_exists;
7+
use Doctrine\Common\Annotations\AnnotationException;
8+
use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader;
9+
use Doctrine\Common\Annotations\AnnotationRegistry;
10+
use Doctrine\Common\Annotations\CachedReader;
11+
use Doctrine\Common\Cache\ApcuCache;
12+
use function function_exists;
13+
use GraphQL\Type\Definition\InputObjectType;
14+
use GraphQL\Type\Definition\ObjectType;
15+
use Psr\Container\ContainerInterface;
16+
use ReflectionClass;
17+
use function str_replace;
18+
use function strpos;
19+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
20+
use Symfony\Component\DependencyInjection\ContainerBuilder;
21+
use Symfony\Component\DependencyInjection\Definition;
22+
use Symfony\Component\DependencyInjection\Reference;
23+
use TheCodingMachine\GraphQLite\AnnotationReader;
24+
use TheCodingMachine\GraphQLite\Annotations\Mutation;
25+
use TheCodingMachine\GraphQLite\Annotations\Query;
26+
use TheCodingMachine\Graphqlite\Bundle\Mappers\ContainerFetcherTypeMapper;
27+
use TheCodingMachine\Graphqlite\Bundle\QueryProviders\ControllerQueryProvider;
28+
use TheCodingMachine\GraphQLite\FieldsBuilderFactory;
29+
use TheCodingMachine\GraphQLite\InputTypeGenerator;
30+
use TheCodingMachine\GraphQLite\InputTypeUtils;
31+
use TheCodingMachine\GraphQLite\Mappers\GlobTypeMapper;
32+
use TheCodingMachine\GraphQLite\Mappers\RecursiveTypeMapperInterface;
33+
use TheCodingMachine\GraphQLite\Mappers\StaticTypeMapper;
34+
use TheCodingMachine\GraphQLite\NamingStrategy;
35+
use TheCodingMachine\GraphQLite\TypeGenerator;
36+
use TheCodingMachine\GraphQLite\Types\MutableObjectType;
37+
use TheCodingMachine\GraphQLite\Types\ResolvableInputObjectType;
38+
use TheCodingMachine\TDBM\Configuration;
39+
use TheCodingMachine\Tdbm\GraphQL\GraphQLTypeAnnotator;
40+
41+
/**
42+
* Detects controllers and types automatically and tag them.
43+
*/
44+
class TdbmGraphqlCompilerPass implements CompilerPassInterface
45+
{
46+
/**
47+
* This Compiler pass adds the GraphQLTypeAnnotator to TDBM configuration
48+
*/
49+
public function process(ContainerBuilder $container)
50+
{
51+
$configuration = $container->findDefinition(Configuration::class);
52+
$arguments = $configuration->getArguments();
53+
54+
$generationListeners = $arguments[7] ?? [];
55+
$codeGenerationListeners = $arguments[9] ?? [];
56+
57+
$generationListeners[] = new Reference(GraphQLTypeAnnotator::class);
58+
$codeGenerationListeners[] = new Reference(GraphQLTypeAnnotator::class);
59+
60+
$configuration->setArgument(7, $generationListeners);
61+
$configuration->setArgument(9, $codeGenerationListeners);
62+
}
63+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\Tdbm\Graphql\Bundle\DependencyInjection;
5+
6+
7+
use Symfony\Component\Config\FileLocator;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\DependencyInjection\Extension\Extension;
10+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
11+
use TheCodingMachine\Tdbm\GraphQL\GraphQLTypeAnnotator;
12+
13+
class TdbmGraphqlExtension extends Extension
14+
{
15+
16+
/**
17+
* Loads a specific configuration.
18+
*
19+
* @throws \InvalidArgumentException When provided tag is not defined in this extension
20+
*/
21+
public function load(array $configs, ContainerBuilder $container)
22+
{
23+
$configuration = new Configuration();
24+
$config = $this->processConfiguration($configuration, $configs);
25+
26+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/container'));
27+
$loader->load('tdbmgraphql.xml');
28+
29+
$definition = $container->getDefinition(GraphQLTypeAnnotator::class);
30+
$definition->replaceArgument(0, $config['type_namespace']);
31+
$definition->replaceArgument(1, $config['generated_type_namespace']);
32+
}
33+
}

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[![Latest Stable Version](https://poser.pugx.org/thecodingmachine/tdbm-graphql-bundle/v/stable)](https://packagist.org/packages/thecodingmachine/tdbm-graphql-bundle)
2+
[![Latest Unstable Version](https://poser.pugx.org/thecodingmachine/tdbm-graphql-bundle/v/unstable)](https://packagist.org/packages/thecodingmachine/tdbm-graphql-bundle)
3+
[![License](https://poser.pugx.org/thecodingmachine/tdbm-graphql-bundle/license)](https://packagist.org/packages/thecodingmachine/tdbm-graphql-bundle)
4+
[![Build Status](https://travis-ci.org/thecodingmachine/tdbm-graphql-bundle.svg?branch=master)](https://travis-ci.org/thecodingmachine/tdbm-graphql-bundle)
5+
[![Coverage Status](https://coveralls.io/repos/thecodingmachine/tdbm-graphql-bundle/badge.svg?branch=master&service=github)](https://coveralls.io/github/thecodingmachine/tdbm-graphql-bundle?branch=master)
6+
7+
8+
# TdbmGraphql bundle
9+
10+
Symfony 4 bundle for the [thecodingmachine/tdbm-graphql](https://github.com/thecodingmachine/tdbm-graphql) package.
11+
12+
See [thecodingmachine/graphqlite](https://github.com/thecodingmachine/graphqlite)
13+
and [thecodingmachine/tdbm](https://thecodingmachine.github.io/tdbm/)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services
6+
http://symfony.com/schema/dic/services/services-1.0.xsd"
7+
>
8+
9+
<services>
10+
<defaults autowire="true" autoconfigure="true" public="false" />
11+
12+
<service id="TheCodingMachine\Tdbm\GraphQL\GraphQLTypeAnnotator">
13+
<argument></argument> <!-- will be filled in with tdbm-graphql.type_namespace dynamically -->
14+
<argument></argument> <!-- will be filled in with tdbm-graphql.generated_type_namespace dynamically -->
15+
</service>
16+
</services>
17+
18+
</container>

TdbmGraphqlBundle.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\Tdbm\Graphql\Bundle;
5+
6+
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\HttpKernel\Bundle\Bundle;
9+
use TheCodingMachine\Tdbm\Graphql\Bundle\DependencyInjection\TdbmGraphqlCompilerPass;
10+
11+
class TdbmGraphqlBundle extends Bundle
12+
{
13+
public function build(ContainerBuilder $container)
14+
{
15+
parent::build($container);
16+
17+
$container->addCompilerPass(new TdbmGraphqlCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
18+
}
19+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\Tdbm\Graphql\Bundle\Tests\Fixtures;
5+
6+
7+
use TheCodingMachine\TDBM\Configuration;
8+
9+
class ExposeConfiguration
10+
{
11+
/**
12+
* @var Configuration
13+
*/
14+
private $configuration;
15+
16+
public function __construct(Configuration $configuration)
17+
{
18+
$this->configuration = $configuration;
19+
}
20+
21+
/**
22+
* @return Configuration
23+
*/
24+
public function getConfiguration(): Configuration
25+
{
26+
return $this->configuration;
27+
}
28+
}

0 commit comments

Comments
 (0)