File tree Expand file tree Collapse file tree 5 files changed +61
-5
lines changed Expand file tree Collapse file tree 5 files changed +61
-5
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ abstract class Node
31
31
32
32
// Values
33
33
34
+ const NULL = 'NullValue ' ;
34
35
const INT = 'IntValue ' ;
35
36
const FLOAT = 'FloatValue ' ;
36
37
const STRING = 'StringValue ' ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace GraphQL \Language \AST ;
4
+
5
+ class NullValue extends Node implements Value
6
+ {
7
+ public $ kind = Node::NULL ;
8
+
9
+ /**
10
+ * @var null
11
+ */
12
+ protected $ value = null ;
13
+
14
+ /**
15
+ * NullValue constructor.
16
+ *
17
+ * @param string $value
18
+ * @param null $loc
19
+ */
20
+ public function __construct ($ loc = null )
21
+ {
22
+ $ this ->loc = $ loc ;
23
+ }
24
+
25
+ /**
26
+ * @return null
27
+ */
28
+ public function getValue ()
29
+ {
30
+ return $ this ->value ;
31
+ }
32
+ }
Original file line number Diff line number Diff line change 10
10
| EnumValue
11
11
| ListValue
12
12
| ObjectValue
13
+ | NullValue
13
14
*/
14
15
interface Value
15
16
{
Original file line number Diff line number Diff line change 27
27
use GraphQL \Language \AST \Name ;
28
28
use GraphQL \Language \AST \NamedType ;
29
29
use GraphQL \Language \AST \NonNullType ;
30
+ use GraphQL \Language \AST \NullValue ;
30
31
use GraphQL \Language \AST \ObjectField ;
31
32
use GraphQL \Language \AST \ObjectTypeDefinition ;
32
33
use GraphQL \Language \AST \ObjectValue ;
@@ -655,14 +656,18 @@ function parseValueLiteral($isConst)
655
656
'value ' => $ token ->value === 'true ' ,
656
657
'loc ' => $ this ->loc ($ token )
657
658
]);
658
- } else if ($ token ->value !== 'null ' ) {
659
+ } else if ($ token ->value === 'null ' ) {
660
+ $ this ->lexer ->advance ();
661
+ return new NullValue (
662
+ $ this ->loc ($ token )
663
+ );
664
+ } else {
659
665
$ this ->lexer ->advance ();
660
666
return new EnumValue ([
661
667
'value ' => $ token ->value ,
662
668
'loc ' => $ this ->loc ($ token )
663
669
]);
664
670
}
665
- break ;
666
671
667
672
case Token::DOLLAR :
668
673
if (!$ isConst ) {
Original file line number Diff line number Diff line change 9
9
use GraphQL \Language \AST \Name ;
10
10
use GraphQL \Language \AST \Node ;
11
11
use GraphQL \Language \AST \OperationDefinition ;
12
+ use GraphQL \Language \AST \NullValue ;
12
13
use GraphQL \Language \AST \SelectionSet ;
13
14
use GraphQL \Language \AST \StringValue ;
14
15
use GraphQL \Language \Parser ;
@@ -112,10 +113,26 @@ public function testDoesNotAcceptFragmentSpreadOfOn()
112
113
/**
113
114
* @it does not allow null as value
114
115
*/
115
- public function testDoesNotAllowNullAsValue ()
116
+ public function testAllowsNullAsValue ()
116
117
{
117
- $ this ->setExpectedException ('GraphQL\Error\SyntaxError ' , 'Syntax Error GraphQL (1:39) Unexpected Name "null" ' );
118
- Parser::parse ('{ fieldWithNullableStringInput(input: null) } ' );
118
+ $ expected = new SelectionSet ([
119
+ 'selections ' => [
120
+ new Field ([
121
+ 'name ' => new Name (['value ' => 'fieldWithNullableStringInput ' ]),
122
+ 'arguments ' => [
123
+ new Argument ([
124
+ 'name ' => new Name (['value ' => 'input ' ]),
125
+ 'value ' => new NullValue ()
126
+ ])
127
+ ],
128
+ 'directives ' => []
129
+ ])
130
+ ]
131
+ ]);
132
+
133
+ $ result = Parser::parse ('{ fieldWithNullableStringInput(input: null) } ' , ['noLocation ' => true ]);
134
+
135
+ $ this ->assertEquals ($ expected , $ result ->definitions [0 ]->selectionSet );
119
136
}
120
137
121
138
/**
You can’t perform that action at this time.
0 commit comments