|
8 | 8 | from graphql.type import (
|
9 | 9 | GraphQLArgument,
|
10 | 10 | GraphQLBoolean,
|
11 |
| - GraphQLDirective, |
12 |
| - GraphQLEnumType, |
13 | 11 | GraphQLEnumValue,
|
14 | 12 | GraphQLField,
|
15 | 13 | GraphQLFloat,
|
16 | 14 | GraphQLID,
|
17 | 15 | GraphQLInputField,
|
18 |
| - GraphQLInputObjectType, |
19 | 16 | GraphQLInt,
|
20 |
| - GraphQLInterfaceType, |
21 |
| - GraphQLList, |
22 | 17 | GraphQLNamedType,
|
23 |
| - GraphQLNonNull, |
24 | 18 | GraphQLObjectType,
|
25 |
| - GraphQLScalarType, |
26 | 19 | GraphQLSchema,
|
27 | 20 | GraphQLString,
|
28 |
| - GraphQLUnionType, |
29 | 21 | assert_directive,
|
30 | 22 | assert_enum_type,
|
31 | 23 | assert_input_object_type,
|
32 | 24 | assert_interface_type,
|
33 | 25 | assert_object_type,
|
34 | 26 | assert_scalar_type,
|
35 | 27 | assert_union_type,
|
36 |
| - specified_directives, |
37 | 28 | validate_schema,
|
38 | 29 | )
|
39 | 30 | from graphql.utilities import build_schema, extend_schema, print_schema
|
40 | 31 |
|
41 | 32 | # Test schema.
|
42 | 33 |
|
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 | + """ |
125 | 83 | )
|
126 | 84 |
|
127 | 85 |
|
@@ -1132,7 +1090,12 @@ def does_not_automatically_include_common_root_type_names():
|
1132 | 1090 | assert schema.mutation_type is None
|
1133 | 1091 |
|
1134 | 1092 | 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 | + ) |
1136 | 1099 | assert schema.query_type is None
|
1137 | 1100 |
|
1138 | 1101 | extension_sdl = dedent(
|
|
0 commit comments