@@ -21,6 +21,10 @@ def test_jsonstring_query():
2121 assert not result .errors
2222 assert result .data == {"json" : json_value }
2323
24+ result = schema .execute ("""{ json(input: "{}") }""" )
25+ assert not result .errors
26+ assert result .data == {"json" : "{}" }
27+
2428
2529def test_jsonstring_query_variable ():
2630 json_value = '{"key": "value"}'
@@ -31,3 +35,51 @@ def test_jsonstring_query_variable():
3135 )
3236 assert not result .errors
3337 assert result .data == {"json" : json_value }
38+
39+
40+ def test_jsonstring_optional_uuid_input ():
41+ """
42+ Test that we can provide a null value to an optional input
43+ """
44+ result = schema .execute ("{ json(input: null) }" )
45+ assert not result .errors
46+ assert result .data == {"json" : None }
47+
48+
49+ def test_jsonstring_invalid_query ():
50+ """
51+ Test that if an invalid type is provided we get an error
52+ """
53+ result = schema .execute ("{ json(input: 1) }" )
54+ assert result .errors
55+ assert len (result .errors ) == 1
56+ assert result .errors [0 ].message == "Expected value of type 'JSONString', found 1."
57+
58+ result = schema .execute ("{ json(input: {}) }" )
59+ assert result .errors
60+ assert len (result .errors ) == 1
61+ assert result .errors [0 ].message == "Expected value of type 'JSONString', found {}."
62+
63+ result = schema .execute ('{ json(input: "a") }' )
64+ assert result .errors
65+ assert len (result .errors ) == 1
66+ assert result .errors [0 ].message == (
67+ "Expected value of type 'JSONString', found \" a\" ; "
68+ "Badly formed JSONString: Expecting value: line 1 column 1 (char 0)"
69+ )
70+
71+ result = schema .execute ("""{ json(input: "{\\ 'key\\ ': 0}") }""" )
72+ assert result .errors
73+ assert len (result .errors ) == 1
74+ assert (
75+ result .errors [0 ].message
76+ == "Syntax Error: Invalid character escape sequence: '\\ ''."
77+ )
78+
79+ result = schema .execute ("""{ json(input: "{\\ "key\\ ": 0,}") }""" )
80+ assert result .errors
81+ assert len (result .errors ) == 1
82+ assert result .errors [0 ].message == (
83+ 'Expected value of type \' JSONString\' , found "{\\ "key\\ ": 0,}"; '
84+ "Badly formed JSONString: Expecting property name enclosed in double quotes: line 1 column 11 (char 10)"
85+ )
0 commit comments