Skip to content

Commit 5442843

Browse files
committed
* Fix type class loader (#46)
* Document Union and InputObject definition
1 parent 7f0794f commit 5442843

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ matrix:
2121
- php: 7.0
2222
env: SYMFONY_VERSION=3.0.*
2323
- php: 7.0
24-
env: SYMFONY_VERSION='3.1.*@dev'
24+
env: SYMFONY_VERSION=3.1.*
2525

2626
allow_failures:
2727
- php: nightly
28-
- env: SYMFONY_VERSION='3.1.*@dev'
2928

3029
cache:
3130
directories:

Generator/TypeGenerator.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Overblog\GraphQLBundle\Generator;
1313

1414
use Overblog\GraphQLGenerator\Generator\TypeGenerator as BaseTypeGenerator;
15-
use Symfony\Component\ClassLoader\ClassCollectionLoader;
1615
use Symfony\Component\ClassLoader\MapClassLoader;
1716
use Symfony\Component\Filesystem\Filesystem;
1817

@@ -150,7 +149,7 @@ function ($childrenComplexity, $args = []) <closureUseStatements> {
150149
return $code;
151150
}
152151

153-
public function compile(array $configs)
152+
public function compile(array $configs, $loadClasses = true)
154153
{
155154
$cacheDir = $this->getCacheDir();
156155
if (file_exists($cacheDir)) {
@@ -159,16 +158,10 @@ public function compile(array $configs)
159158
}
160159

161160
$classes = $this->generateClasses($configs, $cacheDir, true);
161+
file_put_contents($this->getClassesMap(), "<?php\nreturn ".var_export($classes, true).';');
162162

163-
if (!empty($classes)) {
164-
$file = $this->getClassCollectionPath();
165-
166-
$mapClassLoader = new MapClassLoader($classes);
167-
$mapClassLoader->register();
168-
169-
ClassCollectionLoader::load(array_keys($classes), dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
170-
171-
self::$classMapLoaded = true;
163+
if ($loadClasses) {
164+
$this->loadClasses(true);
172165
}
173166

174167
return $classes;
@@ -177,18 +170,17 @@ public function compile(array $configs)
177170
public function loadClasses($forceReload = false)
178171
{
179172
if (!self::$classMapLoaded || $forceReload) {
180-
$classCollectionPath = $this->getClassCollectionPath();
173+
$classes = require $this->getClassesMap();
181174

182-
if (file_exists($classCollectionPath)) {
183-
require_once $classCollectionPath;
184-
}
175+
$mapClassLoader = new MapClassLoader($classes);
176+
$mapClassLoader->register();
185177

186178
self::$classMapLoaded = true;
187179
}
188180
}
189181

190-
private function getClassCollectionPath()
182+
private function getClassesMap()
191183
{
192-
return $this->getCacheDir().'/__types.bootstrap.php.cache';
184+
return $this->getCacheDir().'/__classes.map';
193185
}
194186
}

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,34 @@ Droid:
266266
```
267267
### Union
268268
269-
TODO
269+
```yaml
270+
# src/MyBundle/Resources/config/graphql/HumanAndDroid.types.yml
271+
#
272+
# This implements the following type system shorthand:
273+
# union HumanAndDroid = Human | Droid
274+
HumanAndDroid:
275+
type: union
276+
config:
277+
types: [Human, Droid]
278+
description: Human and Droid
279+
```
280+
281+
### Input object
282+
283+
```yaml
284+
# src/MyBundle/Resources/config/graphql/HumanAndDroid.types.yml
285+
#
286+
# This implements the following type system shorthand:
287+
# type HeroInput {
288+
# name: Episode!
289+
# }
290+
HeroInput:
291+
type: input-object
292+
config:
293+
fields:
294+
name:
295+
type: "Episode!"
296+
```
270297
271298
### Schema
272299

0 commit comments

Comments
 (0)