Skip to content

Commit

Permalink
Fix deprecation callback field types error
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed Nov 28, 2016
1 parent fa42d67 commit 3d758ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/Generator/AbstractTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ abstract class AbstractTypeGenerator extends AbstractClassGenerator
{
const DEFAULT_CLASS_NAMESPACE = 'Overblog\\CG\\GraphQLGenerator\\__Schema__';

protected static $closureTemplate = <<<EOF
function (%s) <closureUseStatements>{
<spaces><spaces>return %s;
<spaces>}
EOF;

private static $typeSystems = [
'object' => 'GraphQL\\Type\\Definition\\ObjectType',
'interface' => 'GraphQL\\Type\\Definition\\InterfaceType',
Expand Down Expand Up @@ -161,7 +167,7 @@ protected function callableCallbackFromArrayValue(array $value, $key, $argDefini
return $default;
}

$code = 'function (%s) <closureUseStatements>{ return %s; }';
$code = static::$closureTemplate;

if (is_callable($value[$key])) {
$func = $value[$key];
Expand Down Expand Up @@ -244,7 +250,7 @@ protected function resolveTypeCode($alias)
protected function resolveTypesCode(array $values, $key)
{
if (isset($values[$key])) {
$types = sprintf('function () <closureUseStatements>{ return %s; }', $this->types2String($values[$key]));
$types = $this->types2String($values[$key]);
} else {
$types = '[]';
}
Expand Down
6 changes: 3 additions & 3 deletions src/Generator/TypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class TypeGenerator extends AbstractTypeGenerator
{
protected function generateOutputFields(array $config)
{
return $this->processFromArray($config['fields'], 'OutputField');
return sprintf(static::$closureTemplate, '', $this->processFromArray($config['fields'], 'OutputField'));
}

protected function generateInputFields(array $config)
{
return $this->processFromArray($config['fields'], 'InputField');
return sprintf(static::$closureTemplate, '', $this->processFromArray($config['fields'], 'InputField'));
}

protected function generateArgs(array $fields)
Expand Down Expand Up @@ -63,7 +63,7 @@ protected function generateType(array $value)
$type = 'null';

if (isset($value['type'])) {
$type = sprintf('function () <closureUseStatements>{ return %s; }', $this->typeAlias2String($value['type']));
$type = sprintf('%s', $this->typeAlias2String($value['type']));
}

return $type;
Expand Down
2 changes: 1 addition & 1 deletion tests/StarWarsIntrospectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function testAllowsQueryingTheSchemaForFieldArgs()
'name' => 'hero',
'args' => [
[
'defaultValue' => null,
'defaultValue' => 'null',
'description' => 'If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.',
'name' => 'episode',
'type' => [
Expand Down

0 comments on commit 3d758ce

Please sign in to comment.