Skip to content

Commit f3b2357

Browse files
authored
Merge pull request #989 from mcg-web/fix-type-shorthand
Add type shorthand failling test
2 parents d914619 + 4cad4e5 commit f3b2357

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

src/Generator/TypeBuilder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,12 @@ public function buildField(array $fieldConfig, string $fieldname)
694694
// Convert to object for better readability
695695
$c = (object) $fieldConfig;
696696

697+
// TODO(any): modify `InputValidator` and `TypeDecoratorListener` to support it before re-enabling this
698+
// see https://github.com/overblog/GraphQLBundle/issues/973
697699
// If there is only 'type', use shorthand
698-
if (1 === count($fieldConfig) && isset($c->type)) {
700+
/*if (1 === count($fieldConfig) && isset($c->type)) {
699701
return $this->buildType($c->type);
700-
}
702+
}*/
701703

702704
$field = Collection::assoc()
703705
->addItem('type', $this->buildType($c->type));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
imports:
2+
- { resource: ../config.yml }
3+
framework:
4+
annotations: true
5+
validation:
6+
enabled: true
7+
enable_annotations: true
8+
9+
overblog_graphql:
10+
errors_handler:
11+
debug: true
12+
definitions:
13+
class_namespace: "Overblog\\GraphQLBundle\\TypeShorthand\\__DEFINITIONS__"
14+
schema:
15+
query: RootQuery
16+
mappings:
17+
types:
18+
-
19+
type: yaml
20+
dir: "%kernel.project_dir%/config/typeShorthand/mapping"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
RootQuery:
2+
type: object
3+
config:
4+
fields:
5+
user:
6+
type: User!
7+
args:
8+
auth:
9+
type: AuthInput!
10+
validation: cascade
11+
resolve: >
12+
@={
13+
"username": args["auth"]["username"],
14+
"address": {
15+
"street": args["auth"]["username"] ~ " foo street",
16+
"zipcode": "12345"
17+
}
18+
}
19+
20+
AuthInput:
21+
type: input-object
22+
config:
23+
fields:
24+
username:
25+
type: String!
26+
validation:
27+
- NotBlank: ~
28+
password: String!
29+
User:
30+
type: object
31+
config:
32+
fields:
33+
username: String!
34+
address: Address!
35+
36+
Address:
37+
type: object
38+
config:
39+
fields:
40+
street: String!
41+
zipcode: String!
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Overblog\GraphQLBundle\Tests\Functional\AutoConfigure;
6+
7+
use Doctrine\Common\Annotations\Reader;
8+
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
9+
use Symfony\Component\Validator\Validation;
10+
11+
class TypeShorthandTest extends TestCase
12+
{
13+
protected function setUp(): void
14+
{
15+
if (!class_exists(Validation::class)) {
16+
$this->markTestSkipped('Symfony validator component is not installed');
17+
}
18+
if (!interface_exists(Reader::class)) {
19+
$this->markTestSkipped('Symfony validator component requires doctrine/annotations but it is not installed');
20+
}
21+
static::bootKernel(['test_case' => 'typeShorthand']);
22+
}
23+
24+
public function testQuery(): void
25+
{
26+
$query = 'query { user(auth: {username: "bar", password: "baz"}) {username, address {street, zipcode}} }';
27+
$expectedData = ['user' => ['username' => 'bar', 'address' => ['street' => 'bar foo street', 'zipcode' => '12345']]];
28+
29+
$this->assertGraphQL($query, $expectedData);
30+
}
31+
}

0 commit comments

Comments
 (0)