Skip to content

Commit 93b9cbf

Browse files
authored
Merge pull request #294 from flow-control/honor-default-values-in-schema
Forward defaultValue to GraphQL Schema
2 parents 0d47d9f + 6d0b0e0 commit 93b9cbf

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/QueryField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(string $name, OutputType $type, array $arguments, ?c
4545
$config = [
4646
'name' => $name,
4747
'type' => $type,
48-
'args' => array_map(function(array $item) { return $item['type']; }, $arguments)
48+
'args' => $arguments,
4949
];
5050
if ($comment) {
5151
$config['description'] = $comment;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace TheCodingMachine\GraphQLite\Fixtures\Integration\Controllers;
4+
5+
use TheCodingMachine\GraphQLite\Annotations\Query;
6+
7+
class DefaultValueController
8+
{
9+
/**
10+
* @Query()
11+
*/
12+
public function defaultValue(string $default = 'value'): string
13+
{
14+
return $default;
15+
}
16+
}

tests/Integration/EndToEndTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,42 @@ public function testEndToEndStaticFactories()
508508
], $result->toArray(Debug::RETHROW_INTERNAL_EXCEPTIONS)['data']);
509509
}
510510

511+
public function testDefaultValueInSchema()
512+
{
513+
/** @var Schema $schema */
514+
$schema = $this->mainContainer->get(Schema::class);
515+
516+
$queryString = '
517+
query deprecatedField {
518+
__type(name: "Query") {
519+
fields {
520+
name
521+
args {
522+
name
523+
defaultValue
524+
}
525+
}
526+
}
527+
}
528+
';
529+
530+
$result = GraphQL::executeQuery(
531+
$schema,
532+
$queryString
533+
);
534+
535+
$defaultField = null;
536+
foreach ($result->data['__type']['fields'] as $field) {
537+
if ($field['name'] === 'defaultValue') {
538+
$defaultField = $field;
539+
break;
540+
}
541+
}
542+
543+
$this->assertSame(
544+
$defaultField['args'][0]['defaultValue'],
545+
'"value"'
546+
);
547+
}
548+
511549
}

0 commit comments

Comments
 (0)