Skip to content

Commit e5eeb9d

Browse files
authored
fix(Decimal): parse integers as decimal. (#1295)
1 parent e0d4bec commit e5eeb9d

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

graphene/types/decimal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from decimal import Decimal as _Decimal
44

5-
from graphql.language.ast import StringValueNode
5+
from graphql.language.ast import StringValueNode, IntValueNode
66

77
from .scalars import Scalar
88

@@ -23,7 +23,7 @@ def serialize(dec):
2323

2424
@classmethod
2525
def parse_literal(cls, node):
26-
if isinstance(node, StringValueNode):
26+
if isinstance(node, (StringValueNode, IntValueNode)):
2727
return cls.parse_value(node.value)
2828

2929
@staticmethod

graphene/types/tests/test_decimal.py

+8
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ def test_bad_decimal_query():
4141
result = schema.execute("""{ decimal(input: "%s") }""" % not_a_decimal)
4242
assert len(result.errors) == 1
4343
assert result.data is None
44+
45+
46+
def test_decimal_string_query_integer():
47+
decimal_value = 1
48+
result = schema.execute("""{ decimal(input: %s) }""" % decimal_value)
49+
assert not result.errors
50+
assert result.data == {"decimal": str(decimal_value)}
51+
assert decimal.Decimal(result.data["decimal"]) == decimal_value

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ deps =
88
setenv =
99
PYTHONPATH = .:{envdir}
1010
commands =
11-
py{36,37}: pytest --cov=graphene graphene examples {posargs}
11+
py{36,37,38}: pytest --cov=graphene graphene examples {posargs}
1212

1313
[testenv:pre-commit]
1414
basepython=python3.7

0 commit comments

Comments
 (0)