File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -106,10 +106,13 @@ def ast_from_serialized_value_untyped(serialized: Any) -> Optional[ValueNode]:
106
106
return BooleanValueNode (value = serialized )
107
107
108
108
if isinstance (serialized , int ):
109
- return IntValueNode (value = f" { serialized :d } " )
109
+ return IntValueNode (value = str ( serialized ) )
110
110
111
111
if isinstance (serialized , float ) and isfinite (serialized ):
112
- return FloatValueNode (value = f"{ serialized :g} " )
112
+ value = str (serialized )
113
+ if value .endswith (".0" ):
114
+ value = value [:- 2 ]
115
+ return FloatValueNode (value = value )
113
116
114
117
if isinstance (serialized , str ):
115
118
return StringValueNode (value = serialized )
Original file line number Diff line number Diff line change 1
1
import pytest
2
2
from graphql import (
3
+ FloatValueNode ,
3
4
GraphQLError ,
5
+ GraphQLFloat ,
4
6
GraphQLID ,
5
7
GraphQLInt ,
6
8
GraphQLList ,
@@ -87,6 +89,20 @@ def test_ast_from_value_with_non_null_type_and_none():
87
89
assert "Received Null value for a Non-Null type Int." in str (exc_info .value )
88
90
89
91
92
+ def test_ast_from_value_float_precision ():
93
+
94
+ # Checking precision of float serialization
95
+ # See https://github.com/graphql-python/graphql-core/pull/164
96
+
97
+ assert ast_from_value (123456789.01234567 , GraphQLFloat ) == FloatValueNode (
98
+ value = "123456789.01234567"
99
+ )
100
+
101
+ assert ast_from_value (1.1 , GraphQLFloat ) == FloatValueNode (value = "1.1" )
102
+
103
+ assert ast_from_value (123.0 , GraphQLFloat ) == FloatValueNode (value = "123" )
104
+
105
+
90
106
def test_ast_from_serialized_value_untyped_typeerror ():
91
107
with pytest .raises (TypeError ) as exc_info :
92
108
ast_from_serialized_value_untyped (GraphQLInt )
You can’t perform that action at this time.
0 commit comments