Skip to content

Commit 14b5e8e

Browse files
committed
test_values_of_correct_type: improve coverage
Replicates graphql/graphql-js@0762193
1 parent f14b53b commit 14b5e8e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/validation/test_values_of_correct_type.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
from functools import partial
22

3+
from graphql.pyutils import Undefined
4+
from graphql.type import (
5+
GraphQLArgument,
6+
GraphQLField,
7+
GraphQLObjectType,
8+
GraphQLSchema,
9+
GraphQLScalarType,
10+
GraphQLString,
11+
)
312
from graphql.validation import ValuesOfCorrectTypeRule
413

514
from .harness import assert_validation_errors
@@ -1022,6 +1031,37 @@ def reports_original_error_for_custom_scalar_which_throws():
10221031
"Invalid scalar is always invalid: 123"
10231032
)
10241033

1034+
def reports_error_for_custom_scalar_that_returns_undefined():
1035+
custom_scalar = GraphQLScalarType(
1036+
"CustomScalar", parse_value=lambda value: Undefined
1037+
)
1038+
1039+
schema = GraphQLSchema(
1040+
GraphQLObjectType(
1041+
"Query",
1042+
{
1043+
"invalidArg": GraphQLField(
1044+
GraphQLString, args={"arg": GraphQLArgument(custom_scalar)}
1045+
)
1046+
},
1047+
)
1048+
)
1049+
1050+
assert_errors(
1051+
"""
1052+
{
1053+
invalidArg(arg: 123)
1054+
}
1055+
""",
1056+
[
1057+
{
1058+
"message": "Expected value of type 'CustomScalar', found 123.",
1059+
"locations": [(3, 35)],
1060+
},
1061+
],
1062+
schema=schema,
1063+
)
1064+
10251065
def allows_custom_scalar_to_accept_complex_literals():
10261066
assert_valid(
10271067
"""

0 commit comments

Comments
 (0)