File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 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]:
106106 return BooleanValueNode (value = serialized )
107107
108108 if isinstance (serialized , int ):
109- return IntValueNode (value = f" { serialized :d } " )
109+ return IntValueNode (value = str ( serialized ) )
110110
111111 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 )
113116
114117 if isinstance (serialized , str ):
115118 return StringValueNode (value = serialized )
Original file line number Diff line number Diff line change 11import pytest
22from graphql import (
3+ FloatValueNode ,
34 GraphQLError ,
5+ GraphQLFloat ,
46 GraphQLID ,
57 GraphQLInt ,
68 GraphQLList ,
@@ -87,6 +89,20 @@ def test_ast_from_value_with_non_null_type_and_none():
8789 assert "Received Null value for a Non-Null type Int." in str (exc_info .value )
8890
8991
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+
90106def test_ast_from_serialized_value_untyped_typeerror ():
91107 with pytest .raises (TypeError ) as exc_info :
92108 ast_from_serialized_value_untyped (GraphQLInt )
You can’t perform that action at this time.
0 commit comments