Skip to content

Commit 6050af4

Browse files
committed
Add support for directives applied on IDL & Schema
1 parent 39f378e commit 6050af4

18 files changed

+246
-77
lines changed

src/Type/Definition/CustomScalarType.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,6 @@
99
*/
1010
class CustomScalarType extends ScalarType
1111
{
12-
/**
13-
* @var array
14-
*/
15-
public $config;
16-
17-
/**
18-
* CustomScalarType constructor.
19-
* @param array $config
20-
*/
21-
function __construct(array $config)
22-
{
23-
$this->name = $config['name'];
24-
$this->config = $config;
25-
parent::__construct();
26-
}
27-
2812
/**
2913
* @param mixed $value
3014
* @return mixed

src/Type/Definition/Directive.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace GraphQL\Type\Definition;
33

4+
use GraphQL\Language\AST\DirectiveDefinitionNode;
5+
46
/**
57
* Class Directive
68
* @package GraphQL\Type\Definition
@@ -157,6 +159,16 @@ public static function getInternalDirectives()
157159
*/
158160
public $args;
159161

162+
/**
163+
* @var DirectiveDefinitionNode|null
164+
*/
165+
public $astNode;
166+
167+
/**
168+
* @var array
169+
*/
170+
public $config;
171+
160172
/**
161173
* Directive constructor.
162174
* @param array $config
@@ -166,5 +178,6 @@ public function __construct(array $config)
166178
foreach ($config as $key => $value) {
167179
$this->{$key} = $value;
168180
}
181+
$this->config = $config;
169182
}
170183
}

src/Type/Definition/EnumType.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace GraphQL\Type\Definition;
33

44
use GraphQL\Error\InvariantViolation;
5+
use GraphQL\Language\AST\EnumTypeDefinitionNode;
56
use GraphQL\Language\AST\EnumValueNode;
67
use GraphQL\Utils\MixedStore;
78
use GraphQL\Utils\Utils;
@@ -12,6 +13,11 @@
1213
*/
1314
class EnumType extends Type implements InputType, OutputType, LeafType
1415
{
16+
/**
17+
* @var EnumTypeDefinitionNode|null
18+
*/
19+
public $astNode;
20+
1521
/**
1622
* @var EnumValueDefinition[]
1723
*/
@@ -27,11 +33,6 @@ class EnumType extends Type implements InputType, OutputType, LeafType
2733
*/
2834
private $nameLookup;
2935

30-
/**
31-
* @var array
32-
*/
33-
public $config;
34-
3536
public function __construct($config)
3637
{
3738
if (!isset($config['name'])) {
@@ -53,6 +54,7 @@ public function __construct($config)
5354

5455
$this->name = $config['name'];
5556
$this->description = isset($config['description']) ? $config['description'] : null;
57+
$this->astNode = isset($config['astNode']) ? $config['astNode'] : null;
5658
$this->config = $config;
5759
}
5860

@@ -91,7 +93,7 @@ public function getValues()
9193

9294
/**
9395
* @param $name
94-
* @return mixed|null
96+
* @return EnumValueDefinition|null
9597
*/
9698
public function getValue($name)
9799
{

src/Type/Definition/EnumValueDefinition.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
namespace GraphQL\Type\Definition;
3+
use GraphQL\Language\AST\EnumValueDefinitionNode;
34
use GraphQL\Utils\Utils;
45

56
/**
@@ -28,6 +29,11 @@ class EnumValueDefinition
2829
*/
2930
public $description;
3031

32+
/**
33+
* @var EnumValueDefinitionNode|null
34+
*/
35+
public $astNode;
36+
3137
/**
3238
* @var array
3339
*/
@@ -39,6 +45,7 @@ public function __construct(array $config)
3945
$this->value = isset($config['value']) ? $config['value'] : null;
4046
$this->deprecationReason = isset($config['deprecationReason']) ? $config['deprecationReason'] : null;
4147
$this->description = isset($config['description']) ? $config['description'] : null;
48+
$this->astNode = isset($config['astNode']) ? $config['astNode'] : null;
4249

4350
$this->config = $config;
4451
}

src/Type/Definition/FieldArgument.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
namespace GraphQL\Type\Definition;
33

44
use GraphQL\Error\InvariantViolation;
5+
use GraphQL\Language\AST\ArgumentNode;
6+
use GraphQL\Language\AST\InputValueDefinitionNode;
57
use GraphQL\Utils\Utils;
68

79

810
/**
911
* Class FieldArgument
1012
*
1113
* @package GraphQL\Type\Definition
12-
* @todo Rename to ArgumentNode as it is also applicable to directives, not only fields
1314
*/
1415
class FieldArgument
1516
{
@@ -28,6 +29,11 @@ class FieldArgument
2829
*/
2930
public $description;
3031

32+
/**
33+
* @var InputValueDefinitionNode|null
34+
*/
35+
public $astNode;
36+
3137
/**
3238
* @var array
3339
*/
@@ -80,6 +86,9 @@ public function __construct(array $def)
8086
case 'description':
8187
$this->description = $value;
8288
break;
89+
case 'astNode':
90+
$this->astNode = $value;
91+
break;
8392
}
8493
}
8594
$this->config = $def;

src/Type/Definition/FieldDefinition.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace GraphQL\Type\Definition;
33
use GraphQL\Error\InvariantViolation;
4+
use GraphQL\Language\AST\FieldDefinitionNode;
5+
use GraphQL\Language\AST\TypeDefinitionNode;
46
use GraphQL\Utils\Utils;
57

68
/**
@@ -48,6 +50,11 @@ class FieldDefinition
4850
*/
4951
public $deprecationReason;
5052

53+
/**
54+
* @var FieldDefinitionNode|null
55+
*/
56+
public $astNode;
57+
5158
/**
5259
* Original field definition config
5360
*
@@ -185,6 +192,7 @@ protected function __construct(array $config)
185192

186193
$this->description = isset($config['description']) ? $config['description'] : null;
187194
$this->deprecationReason = isset($config['deprecationReason']) ? $config['deprecationReason'] : null;
195+
$this->astNode = isset($config['astNode']) ? $config['astNode'] : null;
188196

189197
$this->config = $config;
190198

src/Type/Definition/InputObjectField.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
namespace GraphQL\Type\Definition;
3+
use GraphQL\Language\AST\InputValueDefinitionNode;
34

45
/**
56
* Class InputObjectField
@@ -27,6 +28,11 @@ class InputObjectField
2728
*/
2829
public $type;
2930

31+
/**
32+
* @var InputValueDefinitionNode|null
33+
*/
34+
public $astNode;
35+
3036
/**
3137
* @var array
3238
*/

src/Type/Definition/InputObjectType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace GraphQL\Type\Definition;
33

44
use GraphQL\Error\InvariantViolation;
5+
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
56
use GraphQL\Utils\Utils;
67

78
/**
@@ -16,9 +17,9 @@ class InputObjectType extends Type implements InputType
1617
private $fields;
1718

1819
/**
19-
* @var array
20+
* @var InputObjectTypeDefinitionNode|null
2021
*/
21-
public $config;
22+
public $astNode;
2223

2324
/**
2425
* InputObjectType constructor.
@@ -45,6 +46,7 @@ public function __construct(array $config)
4546

4647
$this->config = $config;
4748
$this->name = $config['name'];
49+
$this->astNode = isset($config['astNode']) ? $config['astNode'] : null;
4850
$this->description = isset($config['description']) ? $config['description'] : null;
4951
}
5052

src/Type/Definition/InterfaceType.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace GraphQL\Type\Definition;
33

44
use GraphQL\Error\InvariantViolation;
5+
use GraphQL\Language\AST\InterfaceTypeDefinitionNode;
56
use GraphQL\Utils\Utils;
67

78
/**
@@ -16,14 +17,9 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
1617
private $fields;
1718

1819
/**
19-
* @var mixed|null
20+
* @var InterfaceTypeDefinitionNode|null
2021
*/
21-
public $description;
22-
23-
/**
24-
* @var array
25-
*/
26-
public $config;
22+
public $astNode;
2723

2824
/**
2925
* InterfaceType constructor.
@@ -49,6 +45,7 @@ public function __construct(array $config)
4945

5046
$this->name = $config['name'];
5147
$this->description = isset($config['description']) ? $config['description'] : null;
48+
$this->astNode = isset($config['astNode']) ? $config['astNode'] : null;
5249
$this->config = $config;
5350
}
5451

src/Type/Definition/ObjectType.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
namespace GraphQL\Type\Definition;
33

44
use GraphQL\Error\InvariantViolation;
5+
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
6+
use GraphQL\Language\AST\TypeExtensionDefinitionNode;
57
use GraphQL\Utils\Utils;
68

79

@@ -63,11 +65,14 @@ class ObjectType extends Type implements OutputType, CompositeType
6365
private $interfaceMap;
6466

6567
/**
66-
* Keeping reference of config for late bindings and custom app-level metadata
67-
*
68-
* @var array
68+
* @var ObjectTypeDefinitionNode|null
69+
*/
70+
public $astNode;
71+
72+
/**
73+
* @var TypeExtensionDefinitionNode[]
6974
*/
70-
public $config;
75+
public $extensionASTNodes;
7176

7277
/**
7378
* @var callable
@@ -106,6 +111,8 @@ public function __construct(array $config)
106111
$this->name = $config['name'];
107112
$this->description = isset($config['description']) ? $config['description'] : null;
108113
$this->resolveFieldFn = isset($config['resolveField']) ? $config['resolveField'] : null;
114+
$this->astNode = isset($config['astNode']) ? $config['astNode'] : null;
115+
$this->extensionASTNodes = isset($config['extensionASTNodes']) ? $config['extensionASTNodes'] : [];
109116
$this->config = $config;
110117
}
111118

0 commit comments

Comments
 (0)