8
8
namespace Magento \Framework \GraphQl \Schema ;
9
9
10
10
use Magento \Framework \GraphQl \ConfigInterface ;
11
- use Magento \Framework \GraphQl \Schema \SchemaGeneratorInterface ;
12
- use Magento \Framework \GraphQl \Schema \Type \Output \OutputMapper ;
13
11
use Magento \Framework \GraphQl \Schema ;
12
+ use Magento \Framework \GraphQl \Schema \Type \Input \InputMapper ;
13
+ use Magento \Framework \GraphQl \Schema \Type \Output \OutputMapper ;
14
14
use Magento \Framework \GraphQl \SchemaFactory ;
15
15
16
16
/**
@@ -28,6 +28,11 @@ class SchemaGenerator implements SchemaGeneratorInterface
28
28
*/
29
29
private $ outputMapper ;
30
30
31
+ /**
32
+ * @var InputMapper
33
+ */
34
+ private $ inputMapper ;
35
+
31
36
/**
32
37
* @var ConfigInterface
33
38
*/
@@ -36,15 +41,18 @@ class SchemaGenerator implements SchemaGeneratorInterface
36
41
/**
37
42
* @param SchemaFactory $schemaFactory
38
43
* @param OutputMapper $outputMapper
44
+ * @param InputMapper $inputMapper
39
45
* @param ConfigInterface $config
40
46
*/
41
47
public function __construct (
42
48
SchemaFactory $ schemaFactory ,
43
49
OutputMapper $ outputMapper ,
50
+ InputMapper $ inputMapper ,
44
51
ConfigInterface $ config
45
52
) {
46
53
$ this ->schemaFactory = $ schemaFactory ;
47
54
$ this ->outputMapper = $ outputMapper ;
55
+ $ this ->inputMapper = $ inputMapper ;
48
56
$ this ->config = $ config ;
49
57
}
50
58
@@ -60,16 +68,30 @@ public function generate() : Schema
60
68
'typeLoader ' => function ($ name ) {
61
69
return $ this ->outputMapper ->getOutputType ($ name );
62
70
},
63
- 'types ' => function () {
64
- //all types should be generated only on introspection
65
- $ typesImplementors = [];
66
- foreach ($ this ->config ->getDeclaredTypeNames () as $ name ) {
67
- $ typesImplementors [] = $ this ->outputMapper ->getOutputType ($ name );
68
- }
69
- return $ typesImplementors ;
70
- }
71
+ 'types ' => $ this ->getTypes ()
71
72
]
72
73
);
73
74
return $ schema ;
74
75
}
76
+
77
+ /**
78
+ * @return array
79
+ * @throws \Magento\Framework\GraphQl\Exception\GraphQlInputException
80
+ */
81
+ private function getTypes ()
82
+ {
83
+ $ typesImplementors = [];
84
+ foreach ($ this ->config ->getDeclaredTypeNames () as $ type ) {
85
+ switch ($ type ['type ' ]) {
86
+ case 'graphql_type ' :
87
+ $ typesImplementors [] = $ this ->outputMapper ->getOutputType ($ type ['name ' ]);
88
+ break ;
89
+ case 'graphql_input ' :
90
+ $ typesImplementors [] = $ this ->inputMapper ->getInputType ($ type ['name ' ]);
91
+ break ;
92
+ }
93
+ }
94
+
95
+ return $ typesImplementors ;
96
+ }
75
97
}
0 commit comments