mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-22 06:30:52 +03:00
Merge pull request #242 from jkimbo/json-custom-scalar-fix
Json custom scalar fix
This commit is contained in:
commit
17ba01570a
|
@ -16,11 +16,11 @@ class JSONString(Scalar):
|
|||
@staticmethod
|
||||
def parse_literal(node):
|
||||
if isinstance(node, ast.StringValue):
|
||||
return json.dumps(node.value)
|
||||
return json.loads(node.value)
|
||||
|
||||
@staticmethod
|
||||
def parse_value(value):
|
||||
return json.dumps(value)
|
||||
return json.loads(value)
|
||||
|
||||
|
||||
class DateTime(Scalar):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import iso8601
|
||||
from graphql.language.ast import StringValue
|
||||
|
||||
from ..custom_scalars import DateTime
|
||||
from ..custom_scalars import DateTime, JSONString
|
||||
|
||||
|
||||
def test_date_time():
|
||||
|
@ -24,3 +24,16 @@ def test_date_time():
|
|||
node = StringValue(test_iso_string)
|
||||
test_dt = DateTime.parse_literal(node)
|
||||
check_datetime(test_dt)
|
||||
|
||||
|
||||
def test_json_string():
|
||||
test_json_string = '{"foo": "bar"}'
|
||||
|
||||
test_object = JSONString().parse_value(test_json_string)
|
||||
assert test_object == {'foo': 'bar'}
|
||||
|
||||
assert JSONString.serialize(test_object) == test_json_string
|
||||
|
||||
node = StringValue(test_json_string)
|
||||
test_object = JSONString.parse_literal(node)
|
||||
assert test_object == {'foo': 'bar'}
|
||||
|
|
Loading…
Reference in New Issue
Block a user