File tree Expand file tree Collapse file tree 2 files changed +107
-2
lines changed Expand file tree Collapse file tree 2 files changed +107
-2
lines changed Original file line number Diff line number Diff line change 2020 * Class Introspection
2121 * @package GraphQL\Introspection
2222 */
23- class Introspection{
23+ class Introspection
24+ {
2425 /**
2526 * @return array
2627 * @throws BadImplementationError
2728 */
28- static public function buildIntrospectionSchemaParts () : array
29+ static public function buildIntrospectionSchemaParts (): array
2930 {
3031 $ __Type = null ;
3132 $ __Field = null ;
@@ -556,6 +557,89 @@ static public function getTypeNameMetaFieldDef(): GraphQLTypeField
556557 {
557558 return self ::buildIntrospectionSchemaParts ()["TypeNameMetaFieldDef " ];
558559 }
560+
561+ static public function getIntrospectionQuery (): string
562+ {
563+ return '
564+ query IntrospectionQuery {
565+ __schema {
566+ queryType { name }
567+ mutationType { name }
568+ subscriptionType { name }
569+ types {
570+ ...FullType
571+ }
572+ directives {
573+ name
574+ description
575+ args {
576+ ...InputValue
577+ }
578+ onOperation
579+ onFragment
580+ onField
581+ }
582+ }
583+ }
584+
585+ fragment FullType on __Type {
586+ kind
587+ name
588+ description
589+ fields(includeDeprecated: true) {
590+ name
591+ description
592+ args {
593+ ...InputValue
594+ }
595+ type {
596+ ...TypeRef
597+ }
598+ isDeprecated
599+ deprecationReason
600+ }
601+ inputFields {
602+ ...InputValue
603+ }
604+ interfaces {
605+ ...TypeRef
606+ }
607+ enumValues(includeDeprecated: true) {
608+ name
609+ description
610+ isDeprecated
611+ deprecationReason
612+ }
613+ possibleTypes {
614+ ...TypeRef
615+ }
616+ }
617+
618+ fragment InputValue on __InputValue {
619+ name
620+ description
621+ type { ...TypeRef }
622+ defaultValue
623+ }
624+
625+ fragment TypeRef on __Type {
626+ kind
627+ name
628+ ofType {
629+ kind
630+ name
631+ ofType {
632+ kind
633+ name
634+ ofType {
635+ kind
636+ name
637+ }
638+ }
639+ }
640+ }
641+ ' ;
642+ }
559643}
560644
561645
Original file line number Diff line number Diff line change 11<?php
22
3+ use GraphQL \Introspection \Introspection ;
34use PHPUnit \Framework \TestCase ;
45use GraphQL \Parser \Parser ;
56use GraphQL \Validation \Validator ;
@@ -198,4 +199,24 @@ public function testAllowsObjectFieldsInInlineFragments()
198199
199200 self ::assertEmpty ($ validator ->getErrors ());
200201 }
202+
203+ /**
204+ * Allows intropection query on schema
205+ */
206+ public function testAllowsIntrospectionOnSchema ()
207+ {
208+ $ query = Introspection::getIntrospectionQuery ();
209+
210+ $ schema = StarWarsSchema::buildSchema ();
211+
212+ $ parser = new Parser ();
213+ $ validator = new Validator ();
214+
215+ $ parser ->parse ($ query );
216+ $ document = $ parser ->getParsedDocument ();
217+
218+ $ validator ->validate ($ schema , $ document );
219+
220+ self ::assertEmpty ($ validator ->getErrors ());
221+ }
201222}
You can’t perform that action at this time.
0 commit comments