Skip to content

Commit a5ba1da

Browse files
committed
Merge schema validation tests with other schema tests
Replicates graphql/graphql-js@8d7a5fd
1 parent 04166d6 commit a5ba1da

File tree

2 files changed

+53
-61
lines changed

2 files changed

+53
-61
lines changed

tests/type/test_definition.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -857,64 +857,3 @@ def rejects_a_non_type_as_nullable_type_of_non_null(type_):
857857
if isinstance(type_, GraphQLNonNull)
858858
else f"Can only create a wrapper for a GraphQLType, but got: {type_}."
859859
)
860-
861-
862-
def describe_type_system_a_schema_must_contain_uniquely_named_types():
863-
def rejects_a_schema_which_redefines_a_built_in_type():
864-
FakeString = GraphQLScalarType("String", serialize=lambda: None)
865-
866-
QueryType = GraphQLObjectType(
867-
"Query",
868-
{"normal": GraphQLField(GraphQLString), "fake": GraphQLField(FakeString)},
869-
)
870-
871-
with raises(TypeError) as exc_info:
872-
GraphQLSchema(QueryType)
873-
msg = str(exc_info.value)
874-
assert msg == (
875-
"Schema must contain unique named types"
876-
f" but contains multiple types named 'String'."
877-
)
878-
879-
def rejects_a_schema_which_defines_an_object_twice():
880-
A = GraphQLObjectType("SameName", {"f": GraphQLField(GraphQLString)})
881-
B = GraphQLObjectType("SameName", {"f": GraphQLField(GraphQLString)})
882-
883-
QueryType = GraphQLObjectType("Query", {"a": A, "b": B})
884-
885-
with raises(TypeError) as exc_info:
886-
GraphQLSchema(QueryType)
887-
msg = str(exc_info.value)
888-
assert msg == (
889-
"Schema must contain unique named types"
890-
f" but contains multiple types named 'SameName'."
891-
)
892-
893-
def rejects_a_schema_with_same_named_objects_implementing_an_interface():
894-
AnotherInterface = GraphQLInterfaceType(
895-
"AnotherInterface", {"f": GraphQLField(GraphQLString)}
896-
)
897-
898-
FirstBadObject = GraphQLObjectType(
899-
"BadObject",
900-
{"f": GraphQLField(GraphQLString)},
901-
interfaces=[AnotherInterface],
902-
)
903-
904-
SecondBadObject = GraphQLObjectType(
905-
"BadObject",
906-
{"f": GraphQLField(GraphQLString)},
907-
interfaces=[AnotherInterface],
908-
)
909-
910-
QueryType = GraphQLObjectType(
911-
"Query", {"iface": GraphQLField(AnotherInterface)}
912-
)
913-
914-
with raises(TypeError) as exc_info:
915-
GraphQLSchema(QueryType, types=[FirstBadObject, SecondBadObject])
916-
msg = str(exc_info.value)
917-
assert msg == (
918-
"Schema must contain unique named types"
919-
f" but contains multiple types named 'BadObject'."
920-
)

tests/type/test_schema.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
GraphQLField,
66
GraphQLInterfaceType,
77
GraphQLObjectType,
8+
GraphQLScalarType,
89
GraphQLSchema,
910
GraphQLString,
1011
GraphQLInputObjectType,
@@ -64,6 +65,58 @@ def checks_the_configuration_for_mistakes():
6465
with raises(Exception):
6566
GraphQLSchema(directives={})
6667

68+
def describe_a_schema_must_contain_uniquely_named_types():
69+
def rejects_a_schema_which_redefines_a_built_in_type():
70+
FakeString = GraphQLScalarType("String", serialize=lambda: None)
71+
72+
QueryType = GraphQLObjectType(
73+
"Query",
74+
{
75+
"normal": GraphQLField(GraphQLString),
76+
"fake": GraphQLField(FakeString),
77+
},
78+
)
79+
80+
with raises(TypeError) as exc_info:
81+
GraphQLSchema(QueryType)
82+
msg = str(exc_info.value)
83+
assert msg == (
84+
"Schema must contain unique named types"
85+
f" but contains multiple types named 'String'."
86+
)
87+
88+
def rejects_a_schema_which_defines_an_object_twice():
89+
types = [
90+
GraphQLObjectType("SameName", {}),
91+
GraphQLObjectType("SameName", {}),
92+
]
93+
94+
with raises(TypeError) as exc_info:
95+
GraphQLSchema(types=types)
96+
msg = str(exc_info.value)
97+
assert msg == (
98+
"Schema must contain unique named types"
99+
f" but contains multiple types named 'SameName'."
100+
)
101+
102+
def rejects_a_schema_which_defines_fields_with_conflicting_types():
103+
fields = {}
104+
QueryType = GraphQLObjectType(
105+
"Query",
106+
{
107+
"a": GraphQLField(GraphQLObjectType("SameName", fields)),
108+
"b": GraphQLField(GraphQLObjectType("SameName", fields)),
109+
},
110+
)
111+
112+
with raises(TypeError) as exc_info:
113+
GraphQLSchema(QueryType)
114+
msg = str(exc_info.value)
115+
assert msg == (
116+
"Schema must contain unique named types"
117+
f" but contains multiple types named 'SameName'."
118+
)
119+
67120
def describe_when_assumed_valid():
68121
def configures_the_schema_to_have_no_errors():
69122
# noinspection PyProtectedMember

0 commit comments

Comments
 (0)