Skip to content

Commit 86b7905

Browse files
committed
add introspection query validation to star wars validation tests
1 parent 000a558 commit 86b7905

File tree

2 files changed

+107
-2
lines changed

2 files changed

+107
-2
lines changed

src/Introspection/Introspection.php

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
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

tests/StarWarsValidationTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use GraphQL\Introspection\Introspection;
34
use PHPUnit\Framework\TestCase;
45
use GraphQL\Parser\Parser;
56
use 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
}

0 commit comments

Comments
 (0)