Skip to content

Commit 53beafa

Browse files
committed
Initial commit
0 parents  commit 53beafa

18 files changed

+734
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor/
2+
/mouf/
3+
/composer.lock
4+
/src/Tests/
5+
/build/
6+
/phpunit.xml

.scrutinizer.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build:
2+
environment:
3+
php:
4+
version: 7.1
5+
6+
checks:
7+
php:
8+
code_rating: true
9+
duplication: true

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: psr2

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: php
2+
php:
3+
- 7.1
4+
cache:
5+
directories:
6+
- $HOME/.composer/cache
7+
env:
8+
matrix:
9+
- PREFER_LOWEST="--prefer-lowest"
10+
- PREFER_LOWEST=""
11+
before_script:
12+
- composer update --prefer-dist $PREFER_LOWEST
13+
script:
14+
- "./vendor/bin/phpunit"
15+
after_script:
16+
- if [ -z "$PREFER_LOWEST" ]; then ./vendor/bin/coveralls -v; fi

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[![Latest Stable Version](https://poser.pugx.org/thecodingmachine/graphql-controllers/v/stable)](https://packagist.org/packages/thecodingmachine/graphql-controllers)
2+
[![Total Downloads](https://poser.pugx.org/thecodingmachine/graphql-controllers/downloads)](https://packagist.org/packages/thecodingmachine/graphql-controllers)
3+
[![Latest Unstable Version](https://poser.pugx.org/thecodingmachine/graphql-controllers/v/unstable)](https://packagist.org/packages/thecodingmachine/graphql-controllers)
4+
[![License](https://poser.pugx.org/thecodingmachine/graphql-controllers/license)](https://packagist.org/packages/thecodingmachine/graphql-controllers)
5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/graphql-controllers/badges/quality-score.png?b=1.x)](https://scrutinizer-ci.com/g/thecodingmachine/graphql-controllers/?branch=1.x)
6+
[![Build Status](https://travis-ci.org/thecodingmachine/graphql-controllers.svg?branch=1.x)](https://travis-ci.org/thecodingmachine/graphql-controllers)
7+
[![Coverage Status](https://coveralls.io/repos/thecodingmachine/graphql-controllers/badge.svg?branch=1.x&service=github)](https://coveralls.io/github/thecodingmachine/graphql-controllers?branch=1.x)
8+
9+
10+
GraphQL controllers
11+
===================
12+
13+
**Work in progress, no stable release yet**
14+
15+
A utility library on top of `Youshido/graphql` library.
16+
17+
This library allows you to write your GraphQL queries in simple to write controllers:
18+
19+
```php
20+
use TheCodingMachine\GraphQL\Controllers\Annotations\Query;
21+
22+
class UserController
23+
{
24+
/**
25+
* @Query()
26+
* @return User[]
27+
*/
28+
public function users(int $limit, int $offset): array
29+
{
30+
// Some code that returns an array of "users".
31+
// This completely replaces the "resolve" method.
32+
}
33+
}
34+
```
35+
36+
37+
Troubleshooting
38+
---------------
39+
40+
### Error: Maximum function nesting level of '100' reached
41+
42+
Youshido's GraphQL library tends to use a very deep stack. This error does not necessarily mean your code is going into an infinite loop.
43+
Simply try to increase the maximum allowed nesting level in your XDebug conf:
44+
45+
```
46+
xdebug.max_nesting_level=500
47+
```

composer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "thecodingmachine/graphql-controllers",
3+
"description": "Write your GraphQL queries in simple to write controllers (using youshido/graphql).",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "David Négrier",
8+
"email": "d.negrier@thecodingmachine.com"
9+
}
10+
],
11+
"require": {
12+
"php": ">=7.1",
13+
"youshido/graphql": "^1.4",
14+
"psr/container": "^1.0",
15+
"doctrine/annotations": "^1.2",
16+
"roave/better-reflection": "dev-master"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^6.1",
20+
"satooshi/php-coveralls": "^1.0"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"TheCodingMachine\\GraphQL\\Controllers\\": "src/"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"TheCodingMachine\\GraphQL\\Controllers\\": "tests/"
30+
}
31+
},
32+
"extra": {
33+
"branch-alias": {
34+
"dev-master": "1.0.x-dev"
35+
}
36+
},
37+
"minimum-stability": "dev",
38+
"prefer-stable": true
39+
}

phpunit.xml.dist

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="vendor/autoload.php"
13+
>
14+
<testsuites>
15+
<testsuite name="Graphql controllers Test Suite">
16+
<directory>./tests/</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<filter>
21+
<whitelist processUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">src/</directory>
23+
</whitelist>
24+
</filter>
25+
<logging>
26+
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
27+
<log type="coverage-clover" target="build/logs/clover.xml"/>
28+
</logging>
29+
</phpunit>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\GraphQL\Controllers;
5+
6+
use phpDocumentor\Reflection\Type;
7+
use phpDocumentor\Reflection\Types\Array_;
8+
use phpDocumentor\Reflection\Types\Mixed;
9+
use phpDocumentor\Reflection\Types\Object_;
10+
use phpDocumentor\Reflection\Types\String_;
11+
use Psr\Container\ContainerInterface;
12+
use Roave\BetterReflection\Reflection\ReflectionClass;
13+
use Roave\BetterReflection\Reflection\ReflectionMethod;
14+
use Doctrine\Common\Annotations\Reader;
15+
use phpDocumentor\Reflection\Types\Integer;
16+
use TheCodingMachine\GraphQL\Controllers\Annotations\Query;
17+
use Youshido\GraphQL\Field\Field;
18+
use Youshido\GraphQL\Type\ListType\ListType;
19+
use Youshido\GraphQL\Type\NonNullType;
20+
use Youshido\GraphQL\Type\Scalar\IntType;
21+
use Youshido\GraphQL\Type\Scalar\StringType;
22+
use Youshido\GraphQL\Type\TypeInterface;
23+
use Youshido\GraphQL\Type\Union\UnionType;
24+
25+
/**
26+
* A query provider that looks into all controllers of your application to fetch queries.
27+
*/
28+
class AggregateControllerQueryProvider implements QueryProviderInterface
29+
{
30+
/**
31+
* @var Reader
32+
*/
33+
private $annotationReader;
34+
/**
35+
* @var TypeMapperInterface
36+
*/
37+
private $typeMapper;
38+
/**
39+
* @var HydratorInterface
40+
*/
41+
private $hydrator;
42+
/**
43+
* @var array|\string[]
44+
*/
45+
private $controllers;
46+
/**
47+
* @var ContainerInterface
48+
*/
49+
private $container;
50+
51+
/**
52+
* @param string[] $controllers A list of controllers name in the container.
53+
*/
54+
public function __construct(array $controllers, ContainerInterface $container, Reader $annotationReader, TypeMapperInterface $typeMapper, HydratorInterface $hydrator)
55+
{
56+
$this->controllers = $controllers;
57+
$this->container = $container;
58+
$this->annotationReader = $annotationReader;
59+
$this->typeMapper = $typeMapper;
60+
$this->hydrator = $hydrator;
61+
}
62+
63+
/**
64+
* @return Field[]
65+
*/
66+
public function getQueries(): array
67+
{
68+
$queryList = [];
69+
70+
foreach ($this->controllers as $controllerName) {
71+
$controller = $this->container->get($controllerName);
72+
$queryProvider = new ControllerQueryProvider($controller, $this->container, $this->annotationReader, $this->typeMapper, $this->hydrator);
73+
$queryList = array_merge($queryList, $queryProvider->getQueries());
74+
}
75+
76+
return $queryList;
77+
}
78+
}

src/Annotations/Query.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\GraphQL\Controllers\Annotations;
5+
6+
/**
7+
* @Annotation
8+
*/
9+
class Query
10+
{
11+
12+
}

0 commit comments

Comments
 (0)