mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-23 01:56:54 +03:00
fix(Decimal): parse integers as decimal. (#1295)
This commit is contained in:
parent
e0d4bec2d8
commit
e5eeb9d831
|
@ -2,7 +2,7 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
from decimal import Decimal as _Decimal
|
from decimal import Decimal as _Decimal
|
||||||
|
|
||||||
from graphql.language.ast import StringValueNode
|
from graphql.language.ast import StringValueNode, IntValueNode
|
||||||
|
|
||||||
from .scalars import Scalar
|
from .scalars import Scalar
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class Decimal(Scalar):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_literal(cls, node):
|
def parse_literal(cls, node):
|
||||||
if isinstance(node, StringValueNode):
|
if isinstance(node, (StringValueNode, IntValueNode)):
|
||||||
return cls.parse_value(node.value)
|
return cls.parse_value(node.value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -41,3 +41,11 @@ def test_bad_decimal_query():
|
||||||
result = schema.execute("""{ decimal(input: "%s") }""" % not_a_decimal)
|
result = schema.execute("""{ decimal(input: "%s") }""" % not_a_decimal)
|
||||||
assert len(result.errors) == 1
|
assert len(result.errors) == 1
|
||||||
assert result.data is None
|
assert result.data is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_decimal_string_query_integer():
|
||||||
|
decimal_value = 1
|
||||||
|
result = schema.execute("""{ decimal(input: %s) }""" % decimal_value)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {"decimal": str(decimal_value)}
|
||||||
|
assert decimal.Decimal(result.data["decimal"]) == decimal_value
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -8,7 +8,7 @@ deps =
|
||||||
setenv =
|
setenv =
|
||||||
PYTHONPATH = .:{envdir}
|
PYTHONPATH = .:{envdir}
|
||||||
commands =
|
commands =
|
||||||
py{36,37}: pytest --cov=graphene graphene examples {posargs}
|
py{36,37,38}: pytest --cov=graphene graphene examples {posargs}
|
||||||
|
|
||||||
[testenv:pre-commit]
|
[testenv:pre-commit]
|
||||||
basepython=python3.7
|
basepython=python3.7
|
||||||
|
|
Loading…
Reference in New Issue
Block a user