1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
from ..json import JSONString
from ..objecttype import ObjectType
from ..schema import Schema
class Query(ObjectType):
json = JSONString(input=JSONString())
def resolve_json(self, info, input):
return input
schema = Schema(query=Query)
def test_jsonstring_query():
json_value = '{"key": "value"}'
json_value_quoted = json_value.replace('"', '\\"')
result = schema.execute("""{ json(input: "%s") }""" % json_value_quoted)
assert not result.errors
assert result.data == {"json": json_value}
def test_jsonstring_query_variable():
json_value = '{"key": "value"}'
result = schema.execute(
"""query Test($json: JSONString){ json(input: $json) }""",
variables={"json": json_value},
)
assert not result.errors
assert result.data == {"json": json_value}
|