Skip to content

Commit 61adcde

Browse files
committed
add function parseValue to GraphQLID
1 parent 268f1dc commit 61adcde

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Types/GraphQLID.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,33 @@ class GraphQLID extends GraphQLScalarType
1010
protected $description = "Default GraphQL ID Type";
1111

1212
public function serialize($outputValue){
13-
if(!is_int($outputValue) and !is_string($outputValue) and $outputValue!==null){
13+
if(!is_string($outputValue) and $outputValue!==null){
1414
throw new GraphQLError(
1515
"Value \"{$outputValue}\" is not of type \"{$this->getName()}\"."
1616
);
1717
}
18-
return strval($outputValue);
18+
return $outputValue;
1919
}
2020

2121
public function parseLiteral($valueNode, $variables)
2222
{
23-
if($valueNode["kind"] !== "StringValue" and $valueNode["kind"] !== "IntValue"){
23+
if($valueNode["kind"] !== "StringValue"){
2424
throw new GraphQLError(
25-
"ID cannot represent a non-string and non-integer value: {$valueNode["value"]}"
25+
"String cannot represent a non string value: {$valueNode["value"]}"
2626
);
2727
}
2828

2929
return $valueNode["value"];
3030
}
31+
32+
public function parseValue($value){
33+
if(!is_string($value) and $value!==null){
34+
throw new GraphQLError(
35+
"Value \"{$value}\" is not of type \"{$this->getName()}\"."
36+
);
37+
}
38+
return $value;
39+
}
3140
}
3241

3342
?>

0 commit comments

Comments
 (0)