Skip to content

Commit b361779

Browse files
committed
test_value_from_ast: improve coverage
Replicates graphql/graphql-js@4623c3d
1 parent 1fb8111 commit b361779

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/utilities/test_value_from_ast.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
GraphQLInt,
1313
GraphQLList,
1414
GraphQLNonNull,
15+
GraphQLScalarType,
1516
GraphQLString,
1617
)
1718
from graphql.utilities import value_from_ast
@@ -46,6 +47,38 @@ def does_not_convert_when_input_coercion_rules_reject_a_value():
4647
assert _value_from("true", GraphQLString) is Undefined
4748
assert _value_from("123.456", GraphQLID) is Undefined
4849

50+
def convert_using_parse_literal_from_a_custom_scalar_type():
51+
def pass_through_parse_literal(node, _vars=None):
52+
assert node.kind == "string_value"
53+
return node.value
54+
55+
pass_through_scalar = GraphQLScalarType(
56+
"PassThroughScalar",
57+
parse_literal=pass_through_parse_literal,
58+
parse_value=lambda value: value,
59+
)
60+
61+
assert _value_from('"value"', pass_through_scalar) == "value"
62+
63+
def throw_parse_literal(_node, _vars=None):
64+
raise RuntimeError("Test")
65+
66+
throw_scalar = GraphQLScalarType(
67+
"ThrowScalar",
68+
parse_literal=throw_parse_literal,
69+
parse_value=lambda value: value,
70+
)
71+
72+
assert _value_from("value", throw_scalar) is Undefined
73+
74+
return_undefined_scalar = GraphQLScalarType(
75+
"ReturnUndefinedScalar",
76+
parse_literal=lambda _node, _vars=None: Undefined,
77+
parse_value=lambda value: value,
78+
)
79+
80+
assert _value_from("value", return_undefined_scalar) is Undefined
81+
4982
def converts_enum_values_according_to_input_coercion_rules():
5083
test_enum = GraphQLEnumType(
5184
"TestColor",

0 commit comments

Comments
 (0)