Skip to content

Commit

Permalink
Merge pull request #17 from andytruong/schema-subscriptionType
Browse files Browse the repository at this point in the history
Added subscriptionType for introspection compatibility
  • Loading branch information
vladar committed Dec 21, 2015
2 parents 68365e2 + 968da9d commit 4591840
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -134,6 +137,11 @@ public function getMutationType()
return $this->mutationSchema;
}

public function getSubscriptionType()
{
return $this->subscriptionSchema;
}

/**
* @param $name
* @return null
Expand Down
7 changes: 7 additions & 0 deletions src/Type/Introspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ public static function _schema()
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()))),
Expand Down
19 changes: 19 additions & 0 deletions tests/Type/IntrospectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ function testExecutesAnIntrospectionQuery()
'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' =>
Expand Down Expand Up @@ -1410,6 +1425,10 @@ public function testExposesDescriptionsOnTypesAndFields()
'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.'
Expand Down

0 comments on commit 4591840

Please sign in to comment.