Skip to content

Commit 42154e4

Browse files
committed
test_extend_schema: replace 'GraphQL*' types with SDL
Replicates graphql/graphql-js@57e7e1b
1 parent 026de2d commit 42154e4

File tree

1 file changed

+55
-92
lines changed

1 file changed

+55
-92
lines changed

tests/utilities/test_extend_schema.py

Lines changed: 55 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -8,120 +8,78 @@
88
from graphql.type import (
99
GraphQLArgument,
1010
GraphQLBoolean,
11-
GraphQLDirective,
12-
GraphQLEnumType,
1311
GraphQLEnumValue,
1412
GraphQLField,
1513
GraphQLFloat,
1614
GraphQLID,
1715
GraphQLInputField,
18-
GraphQLInputObjectType,
1916
GraphQLInt,
20-
GraphQLInterfaceType,
21-
GraphQLList,
2217
GraphQLNamedType,
23-
GraphQLNonNull,
2418
GraphQLObjectType,
25-
GraphQLScalarType,
2619
GraphQLSchema,
2720
GraphQLString,
28-
GraphQLUnionType,
2921
assert_directive,
3022
assert_enum_type,
3123
assert_input_object_type,
3224
assert_interface_type,
3325
assert_object_type,
3426
assert_scalar_type,
3527
assert_union_type,
36-
specified_directives,
3728
validate_schema,
3829
)
3930
from graphql.utilities import build_schema, extend_schema, print_schema
4031

4132
# Test schema.
4233

43-
SomeScalarType = GraphQLScalarType(name="SomeScalar")
44-
45-
SomeInterfaceType: GraphQLInterfaceType = GraphQLInterfaceType(
46-
name="SomeInterface",
47-
fields=lambda: {
48-
"name": GraphQLField(GraphQLString),
49-
"some": GraphQLField(SomeInterfaceType),
50-
},
51-
)
52-
53-
FooType: GraphQLObjectType = GraphQLObjectType(
54-
name="Foo",
55-
interfaces=[SomeInterfaceType],
56-
fields=lambda: {
57-
"name": GraphQLField(GraphQLString),
58-
"some": GraphQLField(SomeInterfaceType),
59-
"tree": GraphQLField(GraphQLNonNull(GraphQLList(FooType))),
60-
},
61-
)
62-
63-
BarType = GraphQLObjectType(
64-
name="Bar",
65-
interfaces=[SomeInterfaceType],
66-
fields=lambda: {
67-
"name": GraphQLField(GraphQLString),
68-
"some": GraphQLField(SomeInterfaceType),
69-
"foo": GraphQLField(FooType),
70-
},
71-
)
72-
73-
BizType = GraphQLObjectType(
74-
name="Biz", fields=lambda: {"fizz": GraphQLField(GraphQLString)}
75-
)
76-
77-
SomeUnionType = GraphQLUnionType(name="SomeUnion", types=[FooType, BizType])
78-
79-
SomeEnumType = GraphQLEnumType(
80-
name="SomeEnum", values={"ONE": GraphQLEnumValue(1), "TWO": GraphQLEnumValue(2)}
81-
)
82-
83-
SomeInputType = GraphQLInputObjectType(
84-
"SomeInput", lambda: {"fooArg": GraphQLInputField(GraphQLString)}
85-
)
86-
87-
FooDirective = GraphQLDirective(
88-
name="foo",
89-
args={"input": GraphQLArgument(SomeInputType)},
90-
is_repeatable=True,
91-
locations=[
92-
DirectiveLocation.SCHEMA,
93-
DirectiveLocation.SCALAR,
94-
DirectiveLocation.OBJECT,
95-
DirectiveLocation.FIELD_DEFINITION,
96-
DirectiveLocation.ARGUMENT_DEFINITION,
97-
DirectiveLocation.INTERFACE,
98-
DirectiveLocation.UNION,
99-
DirectiveLocation.ENUM,
100-
DirectiveLocation.ENUM_VALUE,
101-
DirectiveLocation.INPUT_OBJECT,
102-
DirectiveLocation.INPUT_FIELD_DEFINITION,
103-
],
104-
)
105-
106-
test_schema = GraphQLSchema(
107-
query=GraphQLObjectType(
108-
name="Query",
109-
fields=lambda: {
110-
"foo": GraphQLField(FooType),
111-
"someScalar": GraphQLField(SomeScalarType),
112-
"someUnion": GraphQLField(SomeUnionType),
113-
"someEnum": GraphQLField(SomeEnumType),
114-
"someInterface": GraphQLField(
115-
SomeInterfaceType,
116-
args={"id": GraphQLArgument(GraphQLNonNull(GraphQLID))},
117-
),
118-
"someInput": GraphQLField(
119-
GraphQLString, args={"input": GraphQLArgument(SomeInputType)}
120-
),
121-
},
122-
),
123-
types=[FooType, BarType],
124-
directives=specified_directives + [FooDirective],
34+
test_schema = build_schema(
35+
"""
36+
scalar SomeScalar
37+
38+
interface SomeInterface {
39+
name: String
40+
some: SomeInterface
41+
}
42+
43+
type Foo implements SomeInterface {
44+
name: String
45+
some: SomeInterface
46+
tree: [Foo]!
47+
}
48+
49+
type Bar implements SomeInterface {
50+
name: String
51+
some: SomeInterface
52+
foo: Foo
53+
}
54+
55+
type Biz {
56+
fizz: String
57+
}
58+
59+
union SomeUnion = Foo | Biz
60+
61+
enum SomeEnum {
62+
ONE
63+
TWO
64+
}
65+
66+
input SomeInput {
67+
fooArg: String
68+
}
69+
70+
directive @foo(input: SomeInput) repeatable on SCHEMA | SCALAR | OBJECT |
71+
FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE |
72+
INPUT_OBJECT | INPUT_FIELD_DEFINITION
73+
74+
type Query {
75+
foo: Foo
76+
someScalar: SomeScalar
77+
someUnion: SomeUnion
78+
someEnum: SomeEnum
79+
someInterface(id: ID!): SomeInterface
80+
someInput(input: SomeInput): String
81+
}
82+
"""
12583
)
12684

12785

@@ -1132,7 +1090,12 @@ def does_not_automatically_include_common_root_type_names():
11321090
assert schema.mutation_type is None
11331091

11341092
def adds_schema_definition_missing_in_the_original_schema():
1135-
schema = GraphQLSchema(directives=[FooDirective], types=[FooType])
1093+
schema = build_schema(
1094+
"""
1095+
directive @foo on SCHEMA
1096+
type Foo
1097+
"""
1098+
)
11361099
assert schema.query_type is None
11371100

11381101
extension_sdl = dedent(

0 commit comments

Comments
 (0)