Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/graphql/utilities/ast_from_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def ast_from_value(value: Any, type_: GraphQLInputType) -> Optional[ValueNode]:
if isinstance(serialized, int):
return IntValueNode(value=f"{serialized:d}")
if isinstance(serialized, float) and isfinite(serialized):
return FloatValueNode(value=f"{serialized:g}")
return FloatValueNode(value=f"{serialized:.16g}")

if isinstance(serialized, str):
# Enum types use Enum literals.
Expand Down
4 changes: 4 additions & 0 deletions tests/utilities/test_ast_from_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def converts_float_values_to_float_asts():

assert ast_from_value(1e40, GraphQLFloat) == FloatValueNode(value="1e+40")

assert ast_from_value(123456789.0123456, GraphQLFloat) == FloatValueNode(
value="123456789.0123456"
)

def converts_string_values_to_string_asts():
assert ast_from_value("hello", GraphQLString) == StringValueNode(value="hello")

Expand Down