Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Generator/AbstractTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ protected function varExport($var, $default = null, array $compilerNames = [])
case is_object($var):
return $default;

case is_string($var):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this case please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the Star Wars schema to have a description which would trigger this bug - or would you prefer a more involved test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you for the changes

$string = var_export($var, true);

// handle multi-line strings
$lines = explode("\n", $string);
if (count($lines) > 1) {
$firstLine = array_shift($lines) . "'" . ' . "\n"';
$lastLine = "'" . array_pop($lines);
$lines = array_map(function($s) { return "'" . $s . "'" . ' . "\n"'; }, $lines);
array_unshift($lines, $firstLine);
array_push($lines, $lastLine);
$string = implode(" . \n", $lines);
}

return $string;

default:
return var_export($var, true);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/StarWarsIntrospectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function testAllowsQueryingTheSchemaForFieldArgs()
'args' => [
[
'defaultValue' => 'null',
'description' => 'If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.',
'description' => "If omitted, returns the hero of the whole saga.\nIf provided, returns the hero of that particular episode.\n",
'name' => 'episode',
'type' => [
'kind' => 'ENUM',
Expand Down
4 changes: 3 additions & 1 deletion tests/starWarsSchema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ Query:
args:
episode:
type: "Episode"
description: "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode."
description: |
If omitted, returns the hero of the whole saga.
If provided, returns the hero of that particular episode.
resolve: ["Overblog\\GraphQLGenerator\\Tests\\Resolver", "getHero"]
human:
type: "Human"
Expand Down