Skip to content

Commit 7183169

Browse files
committed
Init README
1 parent c5ff0b0 commit 7183169

File tree

4 files changed

+78
-13
lines changed

4 files changed

+78
-13
lines changed

README.md

+67-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,70 @@
11
OverblogGraphQLPhpGenerator
22
===========================
33

4-
Todo
5-
----
4+
GraphQL PHP types generator...
5+
6+
Requirements
7+
------------
8+
PHP >= 5.4
9+
10+
Installation
11+
------------
12+
13+
```bash
14+
composer require overblog/graphql-php-generator
15+
```
16+
17+
Usage
18+
-----
19+
20+
```php
21+
<?php
22+
$loader = require __DIR__.'/vendor/autoload.php';
23+
24+
use GraphQL\Schema;
25+
use Overblog\GraphQLGenerator\Generator\TypeGenerator;
26+
use Symfony\Component\ExpressionLanguage\Expression;
27+
28+
$configs = [
29+
'Character' => [
30+
'type' => 'interface',
31+
'config' => [
32+
'description' => new Expression('\'A character\' ~ \' in the Star Wars Trilogy\''),
33+
'fields' => [
34+
'id' => ['type' => 'String!', 'description' => 'The id of the character.'],
35+
'name' => ['type' => 'String', 'description' => 'The name of the character.'],
36+
'friends' => ['type' => '[Character]', 'description' => 'The friends of the character.'],
37+
'appearsIn' => ['type' => '[Episode]', 'description' => 'Which movies they appear in.'],
38+
],
39+
'resolveType' => 'Overblog\\GraphQLGenerator\\Tests\\Resolver::resolveType',
40+
],
41+
],
42+
/*...*/
43+
'Query' => [
44+
'type' => 'object',
45+
'config' => [
46+
'description' => 'A humanoid creature in the Star Wars universe or a faction in the Star Wars saga.',
47+
'fields' => [
48+
'hero' => [
49+
'type' => 'Character',
50+
'args' => [
51+
'episode' => [
52+
'type' => 'Episode',
53+
'description' => 'If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.',
54+
],
55+
],
56+
'resolve' => ['Overblog\\GraphQLGenerator\\Tests\\Resolver', 'getHero'],
57+
],
58+
],
59+
],
60+
/*...*/
61+
],
62+
];
63+
64+
$typeGenerator = new TypeGenerator('\\My\\Schema\\NP');
65+
$classesMap = $typeGenerator->generateClasses($configs, __DIR__ . '/cache/types');
66+
67+
$loader->addClassMap($classesMap);
68+
69+
$schema = new Schema(\My\Schema\NP\QueryType::getInstance());
70+
```

composer.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
"bin-dir": "bin"
1616
},
1717
"require": {
18-
"php": "^5.4|~7.0",
19-
"sllh/php-cs-fixer-styleci-bridge": "^1.5",
20-
"webonyx/graphql-php": "^0.6.1"
18+
"php": "^5.4|~7.0"
2119
},
2220
"require-dev": {
2321
"fabpot/php-cs-fixer": "^1.11",
2422
"phpunit/phpunit": "^4.1|^5.1",
25-
"symfony/expression-language": "^3.0",
26-
"symfony/filesystem": "^3.0",
27-
"symfony/process": "^3.0",
28-
"symfony/yaml": "^3.0"
23+
"sllh/php-cs-fixer-styleci-bridge": "^1.5",
24+
"symfony/expression-language": "^2.7|^3.0",
25+
"symfony/filesystem": "^2.7|^3.0",
26+
"symfony/process": "^2.7|^3.0",
27+
"symfony/yaml": "^2.7|^3.0",
28+
"webonyx/graphql-php": "0.6.2"
2929
},
3030
"autoload": {
3131
"psr-4": {

src/ClassUtils.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function shortenClassFromCode($code, callable $callback = null)
4040
return $codeParsed;
4141
}
4242

43-
public static function cleanUseStatement($use)
43+
public static function cleanClasseName($use)
4444
{
4545
return ltrim($use, '\\');
4646
}

src/Generator/AbstractClassGenerator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function getClassNamespace()
6868

6969
public function setClassNamespace($classNamespace)
7070
{
71-
$this->classNamespace = $classNamespace;
71+
$this->classNamespace = ClassUtils::cleanClasseName($classNamespace);
7272

7373
return $this;
7474
}
@@ -138,7 +138,7 @@ public function clearImplements()
138138

139139
public function addUseStatement($useStatement)
140140
{
141-
$cleanUse = ClassUtils::cleanUseStatement($useStatement);
141+
$cleanUse = ClassUtils::cleanClasseName($useStatement);
142142
if (!in_array($cleanUse, $this->useStatements)) {
143143
$this->useStatements[] = $cleanUse;
144144
}
@@ -172,7 +172,7 @@ public function getSkeletonContent($skeleton)
172172

173173
protected function addInternalUseStatement($use)
174174
{
175-
$cleanUse = ClassUtils::cleanUseStatement($use);
175+
$cleanUse = ClassUtils::cleanClasseName($use);
176176
if (!in_array($cleanUse, $this->internalUseStatements)) {
177177
$this->internalUseStatements[] = $cleanUse;
178178
}

0 commit comments

Comments
 (0)