Skip to content

Commit 10c2945

Browse files
committed
Switch test schema from GraphQLSchema to SDL
Replicates graphql/graphql-js@58f691b
1 parent f7ced0a commit 10c2945

File tree

2 files changed

+87
-136
lines changed

2 files changed

+87
-136
lines changed

tests/utilities/test_find_deprecated_usages.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,21 @@
11
from graphql.language import parse
2-
from graphql.type import (
3-
GraphQLEnumType,
4-
GraphQLEnumValue,
5-
GraphQLSchema,
6-
GraphQLObjectType,
7-
GraphQLField,
8-
GraphQLString,
9-
GraphQLArgument,
10-
)
11-
from graphql.utilities import find_deprecated_usages
2+
from graphql.utilities import build_schema, find_deprecated_usages
123

134

145
def describe_find_deprecated_usages():
156

16-
enum_type = GraphQLEnumType(
17-
"EnumType",
18-
{
19-
"ONE": GraphQLEnumValue(),
20-
"TWO": GraphQLEnumValue(deprecation_reason="Some enum reason."),
21-
},
22-
)
23-
24-
schema = GraphQLSchema(
25-
GraphQLObjectType(
26-
"Query",
27-
{
28-
"normalField": GraphQLField(
29-
GraphQLString, args={"enumArg": GraphQLArgument(enum_type)}
30-
),
31-
"deprecatedField": GraphQLField(
32-
GraphQLString, deprecation_reason="Some field reason."
33-
),
34-
},
35-
)
7+
schema = build_schema(
8+
"""
9+
enum EnumType {
10+
ONE
11+
TWO @deprecated(reason: "Some enum reason.")
12+
}
13+
14+
type Query {
15+
normalField(enumArg: EnumType): String
16+
deprecatedField: String @deprecated(reason: "Some field reason.")
17+
}
18+
"""
3619
)
3720

3821
def should_report_empty_set_for_no_deprecated_usages():

tests/validation/test_overlapping_fields_can_be_merged.py

Lines changed: 74 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
from graphql.type import (
2-
GraphQLField,
3-
GraphQLID,
4-
GraphQLInt,
5-
GraphQLInterfaceType,
6-
GraphQLList,
7-
GraphQLNonNull,
8-
GraphQLObjectType,
9-
GraphQLSchema,
10-
GraphQLString,
11-
)
1+
from graphql.utilities import build_schema
122
from graphql.validation import OverlappingFieldsCanBeMergedRule
133
from graphql.validation.rules.overlapping_fields_can_be_merged import (
144
fields_conflict_message,
@@ -529,101 +519,69 @@ def ignores_unknown_fragments():
529519

530520
def describe_return_types_must_be_unambiguous():
531521

532-
SomeBox = GraphQLInterfaceType(
533-
"SomeBox",
534-
lambda: {
535-
"deepBox": GraphQLField(SomeBox),
536-
"unrelatedField": GraphQLField(GraphQLString),
537-
},
538-
)
522+
schema = build_schema(
523+
"""
524+
interface SomeBox {
525+
deepBox: SomeBox
526+
unrelatedField: String
527+
}
539528
540-
StringBox = GraphQLObjectType(
541-
"StringBox",
542-
lambda: {
543-
"scalar": GraphQLField(GraphQLString),
544-
"deepBox": GraphQLField(StringBox),
545-
"unrelatedField": GraphQLField(GraphQLString),
546-
"listStringBox": GraphQLField(GraphQLList(StringBox)),
547-
"stringBox": GraphQLField(StringBox),
548-
"intBox": GraphQLField(IntBox),
549-
},
550-
interfaces=[SomeBox],
551-
)
529+
type StringBox implements SomeBox {
530+
scalar: String
531+
deepBox: StringBox
532+
unrelatedField: String
533+
listStringBox: [StringBox]
534+
stringBox: StringBox
535+
intBox: IntBox
536+
}
552537
553-
IntBox = GraphQLObjectType(
554-
"IntBox",
555-
lambda: {
556-
"scalar": GraphQLField(GraphQLInt),
557-
"deepBox": GraphQLField(IntBox),
558-
"unrelatedField": GraphQLField(GraphQLString),
559-
"listStringBox": GraphQLField(GraphQLList(StringBox)),
560-
"stringBox": GraphQLField(StringBox),
561-
"intBox": GraphQLField(IntBox),
562-
},
563-
interfaces=[SomeBox],
564-
)
538+
type IntBox implements SomeBox {
539+
scalar: Int
540+
deepBox: IntBox
541+
unrelatedField: String
542+
listStringBox: [StringBox]
543+
stringBox: StringBox
544+
intBox: IntBox
545+
}
565546
566-
NonNullStringBox1 = GraphQLInterfaceType(
567-
"NonNullStringBox1", {"scalar": GraphQLField(GraphQLNonNull(GraphQLString))}
568-
)
547+
interface NonNullStringBox1 {
548+
scalar: String!
549+
}
569550
570-
NonNullStringBox1Impl = GraphQLObjectType(
571-
"NonNullStringBox1Impl",
572-
{
573-
"scalar": GraphQLField(GraphQLNonNull(GraphQLString)),
574-
"deepBox": GraphQLField(StringBox),
575-
"unrelatedField": GraphQLField(GraphQLString),
576-
},
577-
interfaces=[SomeBox, NonNullStringBox1],
578-
)
551+
type NonNullStringBox1Impl implements SomeBox & NonNullStringBox1 {
552+
scalar: String!
553+
unrelatedField: String
554+
deepBox: SomeBox
555+
}
579556
580-
NonNullStringBox2 = GraphQLInterfaceType(
581-
"NonNullStringBox2", {"scalar": GraphQLField(GraphQLNonNull(GraphQLString))}
582-
)
557+
interface NonNullStringBox2 {
558+
scalar: String!
559+
}
583560
584-
NonNullStringBox2Impl = GraphQLObjectType(
585-
"NonNullStringBox2Impl",
586-
{
587-
"scalar": GraphQLField(GraphQLNonNull(GraphQLString)),
588-
"unrelatedField": GraphQLField(GraphQLString),
589-
"deepBox": GraphQLField(StringBox),
590-
},
591-
interfaces=[SomeBox, NonNullStringBox2],
592-
)
561+
type NonNullStringBox2Impl implements SomeBox & NonNullStringBox2 {
562+
scalar: String!
563+
unrelatedField: String
564+
deepBox: SomeBox
565+
}
593566
594-
Connection = GraphQLObjectType(
595-
"Connection",
596-
{
597-
"edges": GraphQLField(
598-
GraphQLList(
599-
GraphQLObjectType(
600-
"Edge",
601-
{
602-
"node": GraphQLField(
603-
GraphQLObjectType(
604-
"Node",
605-
{
606-
"id": GraphQLField(GraphQLID),
607-
"name": GraphQLField(GraphQLString),
608-
},
609-
)
610-
)
611-
},
612-
)
613-
)
614-
)
615-
},
616-
)
567+
type Connection {
568+
edges: [Edge]
569+
}
617570
618-
schema = GraphQLSchema(
619-
GraphQLObjectType(
620-
"QueryRoot",
621-
{
622-
"someBox": GraphQLField(SomeBox),
623-
"connection": GraphQLField(Connection),
624-
},
625-
),
626-
types=[IntBox, StringBox, NonNullStringBox1Impl, NonNullStringBox2Impl],
571+
type Edge {
572+
node: Node
573+
}
574+
575+
type Node {
576+
id: ID
577+
name: String
578+
}
579+
580+
type Query {
581+
someBox: SomeBox
582+
connection: Connection
583+
}
584+
"""
627585
)
628586

629587
def conflicting_return_types_which_potentially_overlap():
@@ -1051,12 +1009,16 @@ def error_message_contains_hint_for_alias_conflict():
10511009
)
10521010

10531011
def works_for_field_names_that_are_js_keywords():
1054-
FooType = GraphQLObjectType(
1055-
"Foo", {"constructor": GraphQLField(GraphQLString)}
1056-
)
1012+
schema_with_keywords = build_schema(
1013+
"""
1014+
type Foo {
1015+
constructor: String
1016+
}
10571017
1058-
schema_with_keywords = GraphQLSchema(
1059-
GraphQLObjectType("query", lambda: {"foo": GraphQLField(FooType)})
1018+
type Query {
1019+
foo: Foo
1020+
}
1021+
"""
10601022
)
10611023

10621024
expect_passes_rule_with_schema(
@@ -1072,10 +1034,16 @@ def works_for_field_names_that_are_js_keywords():
10721034
)
10731035

10741036
def works_for_field_names_that_are_python_keywords():
1075-
FooType = GraphQLObjectType("Foo", {"class": GraphQLField(GraphQLString)})
1037+
schema_with_keywords = build_schema(
1038+
"""
1039+
type Foo {
1040+
class: String
1041+
}
10761042
1077-
schema_with_keywords = GraphQLSchema(
1078-
GraphQLObjectType("query", lambda: {"foo": GraphQLField(FooType)})
1043+
type Query {
1044+
foo: Foo
1045+
}
1046+
"""
10791047
)
10801048

10811049
expect_passes_rule_with_schema(

0 commit comments

Comments
 (0)