This commit is contained in:
Austin Snoeyink 2024-11-22 04:56:03 +00:00 committed by GitHub
commit 1582da5428
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -28,6 +28,8 @@ class Decimal(Scalar):
@staticmethod
def parse_value(value):
if value == "":
return None
try:
return _Decimal(value)
except Exception:

View File

@ -66,3 +66,10 @@ def test_decimal_string_query_integer():
assert not result.errors
assert result.data == {"decimal": str(decimal_value)}
assert decimal.Decimal(result.data["decimal"]) == decimal_value
def test_parse_decimal_empty_string():
"""Parsing an empty string should return None"""
result = schema.execute("""{ decimal(input: \"\") }""")
assert not result.errors
assert result.data == {"decimal": None}