Skip to content

Commit fa9b578

Browse files
committed
Fix schema dump with latest webonyx
1 parent f35dda7 commit fa9b578

File tree

6 files changed

+300
-51
lines changed

6 files changed

+300
-51
lines changed

src/Command/GraphQLDumpSchemaCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GraphQL\Utils\SchemaPrinter;
99
use InvalidArgumentException;
1010
use Overblog\GraphQLBundle\Request\Executor as RequestExecutor;
11+
use Overblog\GraphQLBundle\Resolver\TypeResolver;
1112
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\Input\InputInterface;
1314
use Symfony\Component\Console\Input\InputOption;
@@ -27,11 +28,14 @@ final class GraphQLDumpSchemaCommand extends Command
2728
private RequestExecutor $requestExecutor;
2829
private string $baseExportPath;
2930

30-
public function __construct(string $baseExportPath, RequestExecutor $requestExecutor)
31+
public function __construct(string $baseExportPath, RequestExecutor $requestExecutor, TypeResolver $typeResolver)
3132
{
3233
parent::__construct();
3334
$this->baseExportPath = $baseExportPath;
3435
$this->requestExecutor = $requestExecutor;
36+
37+
// Disable exception when an unresolvable types is encoutered. Schema dump will try to access the Query, Mutation and Subscription types and will fail if they are not defined.
38+
$typeResolver->setIgnoreUnresolvableException(true);
3539
}
3640

3741
public function getRequestExecutor(): RequestExecutor

src/Resolver/TypeResolver.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class TypeResolver extends AbstractResolver
1616
private array $cache = [];
1717
private ?string $currentSchemaName = null;
1818
private EventDispatcherInterface $dispatcher;
19+
private bool $ignoreUnresolvableException = false;
1920

2021
public function setDispatcher(EventDispatcherInterface $dispatcher): void
2122
{
@@ -27,6 +28,11 @@ public function setCurrentSchemaName(?string $currentSchemaName): void
2728
$this->currentSchemaName = $currentSchemaName;
2829
}
2930

31+
public function setIgnoreUnresolvableException(bool $ignoreUnresolvableException): void
32+
{
33+
$this->ignoreUnresolvableException = $ignoreUnresolvableException;
34+
}
35+
3036
/**
3137
* @param mixed $solution
3238
*/
@@ -60,10 +66,10 @@ public function resolve($alias): ?Type
6066
return $this->cache[$alias];
6167
}
6268

63-
private function baseType(string $alias): Type
69+
private function baseType(string $alias): ?Type
6470
{
6571
$type = $this->getSolution($alias);
66-
if (null === $type) {
72+
if (null === $type && !$this->ignoreUnresolvableException) {
6773
throw new UnresolvableException(
6874
sprintf('Could not find type with alias "%s". Did you forget to define it?', $alias)
6975
);

src/Resources/config/commands.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
arguments:
77
- "%kernel.cache_dir%/../.."
88
- '@Overblog\GraphQLBundle\Request\Executor'
9+
- '@Overblog\GraphQLBundle\Resolver\TypeResolver'
910
tags:
1011
- { name: console.command, command: graphql:dump-schema, alias: "graph:dump-schema" }
1112

tests/Functional/Command/fixtures/schema.descriptions.json

Lines changed: 98 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858
"name": "String",
5959
"ofType": null
6060
},
61-
"defaultValue": null
61+
"defaultValue": null,
62+
"isDeprecated": false,
63+
"deprecationReason": null
6264
},
6365
{
6466
"name": "first",
@@ -68,7 +70,9 @@
6870
"name": "Int",
6971
"ofType": null
7072
},
71-
"defaultValue": null
73+
"defaultValue": null,
74+
"isDeprecated": false,
75+
"deprecationReason": null
7276
},
7377
{
7478
"name": "before",
@@ -78,7 +82,9 @@
7882
"name": "String",
7983
"ofType": null
8084
},
81-
"defaultValue": null
85+
"defaultValue": null,
86+
"isDeprecated": false,
87+
"deprecationReason": null
8288
},
8389
{
8490
"name": "last",
@@ -88,7 +94,9 @@
8894
"name": "Int",
8995
"ofType": null
9096
},
91-
"defaultValue": null
97+
"defaultValue": null,
98+
"isDeprecated": false,
99+
"deprecationReason": null
92100
}
93101
],
94102
"type": {
@@ -111,7 +119,9 @@
111119
"name": "String",
112120
"ofType": null
113121
},
114-
"defaultValue": null
122+
"defaultValue": null,
123+
"isDeprecated": false,
124+
"deprecationReason": null
115125
},
116126
{
117127
"name": "first",
@@ -121,7 +131,9 @@
121131
"name": "Int",
122132
"ofType": null
123133
},
124-
"defaultValue": null
134+
"defaultValue": null,
135+
"isDeprecated": false,
136+
"deprecationReason": null
125137
}
126138
],
127139
"type": {
@@ -144,7 +156,9 @@
144156
"name": "String",
145157
"ofType": null
146158
},
147-
"defaultValue": null
159+
"defaultValue": null,
160+
"isDeprecated": false,
161+
"deprecationReason": null
148162
},
149163
{
150164
"name": "last",
@@ -154,7 +168,9 @@
154168
"name": "Int",
155169
"ofType": null
156170
},
157-
"defaultValue": null
171+
"defaultValue": null,
172+
"isDeprecated": false,
173+
"deprecationReason": null
158174
}
159175
],
160176
"type": {
@@ -632,7 +648,9 @@
632648
"name": "Boolean",
633649
"ofType": null
634650
},
635-
"defaultValue": "false"
651+
"defaultValue": "false",
652+
"isDeprecated": false,
653+
"deprecationReason": null
636654
}
637655
],
638656
"type": {
@@ -703,7 +721,9 @@
703721
"name": "Boolean",
704722
"ofType": null
705723
},
706-
"defaultValue": "false"
724+
"defaultValue": "false",
725+
"isDeprecated": false,
726+
"deprecationReason": null
707727
}
708728
],
709729
"type": {
@@ -725,7 +745,20 @@
725745
{
726746
"name": "inputFields",
727747
"description": null,
728-
"args": [],
748+
"args": [
749+
{
750+
"name": "includeDeprecated",
751+
"description": null,
752+
"type": {
753+
"kind": "SCALAR",
754+
"name": "Boolean",
755+
"ofType": null
756+
},
757+
"defaultValue": "false",
758+
"isDeprecated": false,
759+
"deprecationReason": null
760+
}
761+
],
729762
"type": {
730763
"kind": "LIST",
731764
"name": null,
@@ -855,7 +888,20 @@
855888
{
856889
"name": "args",
857890
"description": null,
858-
"args": [],
891+
"args": [
892+
{
893+
"name": "includeDeprecated",
894+
"description": null,
895+
"type": {
896+
"kind": "SCALAR",
897+
"name": "Boolean",
898+
"ofType": null
899+
},
900+
"defaultValue": "false",
901+
"isDeprecated": false,
902+
"deprecationReason": null
903+
}
904+
],
859905
"type": {
860906
"kind": "NON_NULL",
861907
"name": null,
@@ -986,6 +1032,34 @@
9861032
},
9871033
"isDeprecated": false,
9881034
"deprecationReason": null
1035+
},
1036+
{
1037+
"name": "isDeprecated",
1038+
"description": null,
1039+
"args": [],
1040+
"type": {
1041+
"kind": "NON_NULL",
1042+
"name": null,
1043+
"ofType": {
1044+
"kind": "SCALAR",
1045+
"name": "Boolean",
1046+
"ofType": null
1047+
}
1048+
},
1049+
"isDeprecated": false,
1050+
"deprecationReason": null
1051+
},
1052+
{
1053+
"name": "deprecationReason",
1054+
"description": null,
1055+
"args": [],
1056+
"type": {
1057+
"kind": "SCALAR",
1058+
"name": "String",
1059+
"ofType": null
1060+
},
1061+
"isDeprecated": false,
1062+
"deprecationReason": null
9891063
}
9901064
],
9911065
"inputFields": null,
@@ -1306,7 +1380,9 @@
13061380
"ofType": null
13071381
}
13081382
},
1309-
"defaultValue": null
1383+
"defaultValue": null,
1384+
"isDeprecated": false,
1385+
"deprecationReason": null
13101386
}
13111387
],
13121388
"locations": [
@@ -1331,7 +1407,9 @@
13311407
"ofType": null
13321408
}
13331409
},
1334-
"defaultValue": null
1410+
"defaultValue": null,
1411+
"isDeprecated": false,
1412+
"deprecationReason": null
13351413
}
13361414
],
13371415
"locations": [
@@ -1352,12 +1430,16 @@
13521430
"name": "String",
13531431
"ofType": null
13541432
},
1355-
"defaultValue": "\"No longer supported\""
1433+
"defaultValue": "\"No longer supported\"",
1434+
"isDeprecated": false,
1435+
"deprecationReason": null
13561436
}
13571437
],
13581438
"locations": [
13591439
"FIELD_DEFINITION",
1360-
"ENUM_VALUE"
1440+
"ENUM_VALUE",
1441+
"ARGUMENT_DEFINITION",
1442+
"INPUT_FIELD_DEFINITION"
13611443
]
13621444
}
13631445
]

0 commit comments

Comments
 (0)