55namespace GraphQL \Type ;
66
77use Exception ;
8+ use GraphQL \GraphQL ;
89use GraphQL \Language \DirectiveLocation ;
910use GraphQL \Language \Printer ;
1011use GraphQL \Type \Definition \Directive ;
@@ -184,6 +185,34 @@ public static function getTypes()
184185 ];
185186 }
186187
188+ /**
189+ * Build an introspection query from a Schema
190+ *
191+ * Introspection is useful for utilities that care about type and field
192+ * relationships, but do not need to traverse through those relationships.
193+ *
194+ * This is the inverse of BuildClientSchema::build(). The primary use case is outside
195+ * of the server context, for instance when doing schema comparisons.
196+ *
197+ * Options:
198+ * - descriptions
199+ * Whether to include descriptions in the introspection result.
200+ * Default: true
201+ *
202+ * @param array<string, bool> $options
203+ *
204+ * @return array<string, array<mixed>>|null
205+ */
206+ public static function fromSchema (Schema $ schema , array $ options = []) : ?array
207+ {
208+ $ result = GraphQL::executeQuery (
209+ $ schema ,
210+ self ::getIntrospectionQuery ($ options )
211+ );
212+
213+ return $ result ->data ;
214+ }
215+
187216 public static function _schema ()
188217 {
189218 if (! isset (self ::$ map ['__Schema ' ])) {
@@ -263,7 +292,7 @@ public static function _type()
263292 'resolve ' => static function (Type $ type ) {
264293 switch (true ) {
265294 case $ type instanceof ListOfType:
266- return TypeKind::LIST_KIND ;
295+ return TypeKind::LIST ;
267296 case $ type instanceof NonNull:
268297 return TypeKind::NON_NULL ;
269298 case $ type instanceof ScalarType:
@@ -275,7 +304,7 @@ public static function _type()
275304 case $ type instanceof InputObjectType:
276305 return TypeKind::INPUT_OBJECT ;
277306 case $ type instanceof InterfaceType:
278- return TypeKind::INTERFACE_KIND ;
307+ return TypeKind::INTERFACE ;
279308 case $ type instanceof UnionType:
280309 return TypeKind::UNION ;
281310 default :
@@ -408,7 +437,7 @@ public static function _typeKind()
408437 'description ' => 'Indicates this type is an object. `fields` and `interfaces` are valid fields. ' ,
409438 ],
410439 'INTERFACE ' => [
411- 'value ' => TypeKind::INTERFACE_KIND ,
440+ 'value ' => TypeKind::INTERFACE ,
412441 'description ' => 'Indicates this type is an interface. `fields` and `possibleTypes` are valid fields. ' ,
413442 ],
414443 'UNION ' => [
@@ -424,7 +453,7 @@ public static function _typeKind()
424453 'description ' => 'Indicates this type is an input object. `inputFields` is a valid field. ' ,
425454 ],
426455 'LIST ' => [
427- 'value ' => TypeKind::LIST_KIND ,
456+ 'value ' => TypeKind::LIST ,
428457 'description ' => 'Indicates this type is a list. `ofType` is a valid field. ' ,
429458 ],
430459 'NON_NULL ' => [
0 commit comments