diff --git a/src/Schema.php b/src/Schema.php index f177689..a3e9246 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -20,15 +20,18 @@ class Schema protected $mutationSchema; + protected $subscriptionSchema; + protected $_typeMap; protected $_directives; - public function __construct(Type $querySchema = null, Type $mutationSchema = null) + public function __construct(Type $querySchema = null, Type $mutationSchema = null, Type $subscriptionSchema = null) { Utils::invariant($querySchema || $mutationSchema, "Either query or mutation type must be set"); $this->querySchema = $querySchema; $this->mutationSchema = $mutationSchema; + $this->subscriptionSchema = $subscriptionSchema; // Build type map now to detect any errors within this schema. $map = []; @@ -134,6 +137,11 @@ class Schema return $this->mutationSchema; } + public function getSubscriptionType() + { + return $this->subscriptionSchema; + } + /** * @param $name * @return null diff --git a/src/Type/Introspection.php b/src/Type/Introspection.php index dbd85fb..7ed12fc 100644 --- a/src/Type/Introspection.php +++ b/src/Type/Introspection.php @@ -225,6 +225,13 @@ EOD; return $schema->getMutationType(); } ], + 'subscriptionType' => [ + 'description' => 'If this server support subscription, the type that subscription operations will be rooted at.', + 'type' => self::_type(), + 'resolve' => function (Schema $schema) { + return $schema->getSubscriptionType(); + }, + ], 'directives' => [ 'description' => 'A list of all directives supported by this server.', 'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_directive()))), diff --git a/tests/Type/IntrospectionTest.php b/tests/Type/IntrospectionTest.php index 1f1c0e5..02eabef 100644 --- a/tests/Type/IntrospectionTest.php +++ b/tests/Type/IntrospectionTest.php @@ -116,6 +116,21 @@ class IntrospectionTest extends \PHPUnit_Framework_TestCase 'deprecationReason' => NULL, ), 3 => + array( + 'name' => 'subscriptionType', + 'args' => + array( + ), + 'type' => + array( + 'kind' => 'OBJECT', + 'name' => '__Type', + 'ofType' => NULL, + ), + 'isDeprecated' => false, + 'deprecationReason' => NULL, + ), + 4 => array ( 'name' => 'directives', 'args' => @@ -1410,6 +1425,10 @@ class IntrospectionTest extends \PHPUnit_Framework_TestCase 'description' => 'If this server supports mutation, the type that ' . 'mutation operations will be rooted at.' ], + [ + 'name' => 'subscriptionType', + 'description' => 'If this server support subscription, the type that subscription operations will be rooted at.' + ], [ 'name' => 'directives', 'description' => 'A list of all directives supported by this server.'