Skip to content

Commit 4591840

Browse files
committed
Merge pull request #17 from andytruong/schema-subscriptionType
Added subscriptionType for introspection compatibility
2 parents 68365e2 + 968da9d commit 4591840

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/Schema.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ class Schema
2020

2121
protected $mutationSchema;
2222

23+
protected $subscriptionSchema;
24+
2325
protected $_typeMap;
2426

2527
protected $_directives;
2628

27-
public function __construct(Type $querySchema = null, Type $mutationSchema = null)
29+
public function __construct(Type $querySchema = null, Type $mutationSchema = null, Type $subscriptionSchema = null)
2830
{
2931
Utils::invariant($querySchema || $mutationSchema, "Either query or mutation type must be set");
3032
$this->querySchema = $querySchema;
3133
$this->mutationSchema = $mutationSchema;
34+
$this->subscriptionSchema = $subscriptionSchema;
3235

3336
// Build type map now to detect any errors within this schema.
3437
$map = [];
@@ -134,6 +137,11 @@ public function getMutationType()
134137
return $this->mutationSchema;
135138
}
136139

140+
public function getSubscriptionType()
141+
{
142+
return $this->subscriptionSchema;
143+
}
144+
137145
/**
138146
* @param $name
139147
* @return null

src/Type/Introspection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ public static function _schema()
225225
return $schema->getMutationType();
226226
}
227227
],
228+
'subscriptionType' => [
229+
'description' => 'If this server support subscription, the type that subscription operations will be rooted at.',
230+
'type' => self::_type(),
231+
'resolve' => function (Schema $schema) {
232+
return $schema->getSubscriptionType();
233+
},
234+
],
228235
'directives' => [
229236
'description' => 'A list of all directives supported by this server.',
230237
'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_directive()))),

tests/Type/IntrospectionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ function testExecutesAnIntrospectionQuery()
116116
'deprecationReason' => NULL,
117117
),
118118
3 =>
119+
array(
120+
'name' => 'subscriptionType',
121+
'args' =>
122+
array(
123+
),
124+
'type' =>
125+
array(
126+
'kind' => 'OBJECT',
127+
'name' => '__Type',
128+
'ofType' => NULL,
129+
),
130+
'isDeprecated' => false,
131+
'deprecationReason' => NULL,
132+
),
133+
4 =>
119134
array (
120135
'name' => 'directives',
121136
'args' =>
@@ -1410,6 +1425,10 @@ public function testExposesDescriptionsOnTypesAndFields()
14101425
'description' => 'If this server supports mutation, the type that ' .
14111426
'mutation operations will be rooted at.'
14121427
],
1428+
[
1429+
'name' => 'subscriptionType',
1430+
'description' => 'If this server support subscription, the type that subscription operations will be rooted at.'
1431+
],
14131432
[
14141433
'name' => 'directives',
14151434
'description' => 'A list of all directives supported by this server.'

0 commit comments

Comments
 (0)