33namespace GraphQL \SchemaGenerator ;
44
55use GraphQL \Client ;
6+ use GraphQL \SchemaGenerator \SchemaInspector \TypeSubQueryGenerator ;
67
78/**
89 * Class SchemaInspector
1314 */
1415class SchemaInspector
1516{
16- private const TYPE_SUB_QUERY = <<<QUERY
17- type{
18- name
19- kind
20- description
21- ofType{
22- name
23- kind
24- ofType{
25- name
26- kind
27- ofType{
28- name
29- kind
30- ofType{
31- name
32- kind
33- }
34- }
35- }
36- }
37- }
38- QUERY ;
39-
4017
4118 /**
4219 * @var Client
4320 */
4421 protected $ client ;
4522
23+ /**
24+ * @var TypeSubQueryGenerator
25+ */
26+ private $ typeSubQueryGenerate ;
27+
28+
4629 /**
4730 * SchemaInspector constructor.
4831 *
49- * @param Client $client
32+ * @param Client $client
33+ * @param TypeSubQueryGenerator|null $typeSubQueryGenerate Generator of sub queries for types
5034 */
51- public function __construct (Client $ client )
35+ public function __construct (Client $ client, ? TypeSubQueryGenerator $ typeSubQueryGenerate = null )
5236 {
5337 $ this ->client = $ client ;
38+ $ this ->typeSubQueryGenerate = ($ typeSubQueryGenerate ?? new TypeSubQueryGenerator (4 ));
39+
40+ }
41+ // End __construct()
42+
43+
44+ /**
45+ * @return string
46+ */
47+ private function getTypeSubQuery (): string
48+ {
49+ return $ this ->typeSubQueryGenerate ->getSubTypeQuery ();
50+
5451 }
52+ // End getTypeSubQuery()
53+
5554
5655 /**
5756 * @return array
@@ -69,12 +68,12 @@ public function getQueryTypeSchema(): array
6968 description
7069 isDeprecated
7170 deprecationReason
72- " . static :: TYPE_SUB_QUERY . "
71+ ". $ this -> getTypeSubQuery (). "
7372 args{
7473 name
7574 description
7675 defaultValue
77- " . static :: TYPE_SUB_QUERY . "
76+ ". $ this -> getTypeSubQuery (). "
7877 }
7978 }
8079 }
@@ -83,10 +82,13 @@ public function getQueryTypeSchema(): array
8382 $ response = $ this ->client ->runRawQuery ($ schemaQuery , true );
8483
8584 return $ response ->getData ()['__schema ' ]['queryType ' ];
85+
8686 }
87+ // End getQueryTypeSchema()
88+
8789
8890 /**
89- * @param string $objectName
91+ * @param string $objectName The name of the object
9092 *
9193 * @return array
9294 */
@@ -101,23 +103,26 @@ public function getObjectSchema(string $objectName): array
101103 description
102104 isDeprecated
103105 deprecationReason
104- " . static :: TYPE_SUB_QUERY . "
106+ ". $ this -> getTypeSubQuery (). "
105107 args{
106108 name
107109 description
108110 defaultValue
109- " . static :: TYPE_SUB_QUERY . "
111+ ". $ this -> getTypeSubQuery (). "
110112 }
111113 }
112114 }
113115} " ;
114116 $ response = $ this ->client ->runRawQuery ($ schemaQuery , true );
115117
116118 return $ response ->getData ()['__type ' ];
119+
117120 }
121+ // End getObjectSchema()
122+
118123
119124 /**
120- * @param string $objectName
125+ * @param string $objectName The name of the object
121126 *
122127 * @return array
123128 */
@@ -131,17 +136,20 @@ public function getInputObjectSchema(string $objectName): array
131136 name
132137 description
133138 defaultValue
134- " . static :: TYPE_SUB_QUERY . "
139+ ". $ this -> getTypeSubQuery (). "
135140 }
136141 }
137142} " ;
138143 $ response = $ this ->client ->runRawQuery ($ schemaQuery , true );
139144
140145 return $ response ->getData ()['__type ' ];
146+
141147 }
148+ // End getInputObjectSchema()
149+
142150
143151 /**
144- * @param string $objectName
152+ * @param string $objectName The name of the enum object
145153 *
146154 * @return array
147155 */
@@ -160,10 +168,13 @@ enumValues {
160168 $ response = $ this ->client ->runRawQuery ($ schemaQuery , true );
161169
162170 return $ response ->getData ()['__type ' ];
171+
163172 }
173+ //end getEnumObjectSchema()
174+
164175
165176 /**
166- * @param string $objectName
177+ * @param string $objectName The name of the union object
167178 *
168179 * @return array
169180 */
@@ -182,5 +193,9 @@ public function getUnionObjectSchema(string $objectName): array
182193 $ response = $ this ->client ->runRawQuery ($ schemaQuery , true );
183194
184195 return $ response ->getData ()['__type ' ];
196+
185197 }
198+ //end getUnionObjectSchema()
199+
200+
186201}
0 commit comments