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 20
20
* Class Introspection
21
21
* @package GraphQL\Introspection
22
22
*/
23
- class Introspection{
23
+ class Introspection
24
+ {
24
25
/**
25
26
* @return array
26
27
* @throws BadImplementationError
27
28
*/
28
- static public function buildIntrospectionSchemaParts () : array
29
+ static public function buildIntrospectionSchemaParts (): array
29
30
{
30
31
$ __Type = null ;
31
32
$ __Field = null ;
@@ -556,6 +557,89 @@ static public function getTypeNameMetaFieldDef(): GraphQLTypeField
556
557
{
557
558
return self ::buildIntrospectionSchemaParts ()["TypeNameMetaFieldDef " ];
558
559
}
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
+ }
559
643
}
560
644
561
645
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ use GraphQL \Introspection \Introspection ;
3
4
use PHPUnit \Framework \TestCase ;
4
5
use GraphQL \Parser \Parser ;
5
6
use GraphQL \Validation \Validator ;
@@ -198,4 +199,24 @@ public function testAllowsObjectFieldsInInlineFragments()
198
199
199
200
self ::assertEmpty ($ validator ->getErrors ());
200
201
}
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
+ }
201
222
}
You can’t perform that action at this time.
0 commit comments