mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 03:23:55 +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 graphql.language.ast import StringValueNode
|
||||
from graphql.language.ast import StringValueNode, IntValueNode
|
||||
|
||||
from .scalars import Scalar
|
||||
|
||||
|
@ -23,7 +23,7 @@ class Decimal(Scalar):
|
|||
|
||||
@classmethod
|
||||
def parse_literal(cls, node):
|
||||
if isinstance(node, StringValueNode):
|
||||
if isinstance(node, (StringValueNode, IntValueNode)):
|
||||
return cls.parse_value(node.value)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -41,3 +41,11 @@ def test_bad_decimal_query():
|
|||
result = schema.execute("""{ decimal(input: "%s") }""" % not_a_decimal)
|
||||
assert len(result.errors) == 1
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user