1
1
use apollo_compiler:: Schema ;
2
2
3
+ fn validate_schema ( schema : Schema ) {
4
+ let validated_schema = schema. validate ( ) . unwrap ( ) ;
5
+
6
+ // Test the `Schema::to_string()` with orphan extensions by parsing and validating the printed
7
+ // schema.
8
+ let printed_schema = validated_schema. to_string ( ) ;
9
+ Schema :: builder ( )
10
+ . adopt_orphan_extensions ( )
11
+ . parse ( printed_schema, "printed_schema.graphql" )
12
+ . build ( )
13
+ . unwrap ( )
14
+ . validate ( )
15
+ . unwrap ( ) ;
16
+ }
17
+
3
18
#[ test]
4
19
fn test_orphan_extensions ( ) {
5
20
let input = r#"
6
21
extend schema @dir { query: Q }
7
22
extend type Obj @dir { foo: String }
8
- directive @dir on SCHEMA | OBJECT
23
+ extend interface I @dir { foo: String }
24
+ extend union U @dir = Obj
25
+ extend enum E @dir { FOO, BAR }
26
+ extend input Input @dir { bar: String }
27
+ directive @dir on SCHEMA | SCALAR | OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT
9
28
type Q { x: Int }
10
29
"# ;
11
30
@@ -31,7 +50,7 @@ fn test_orphan_extensions() {
31
50
. unwrap ( ) ;
32
51
assert ! ( schema2. schema_definition. directives. has( "dir" ) ) ;
33
52
assert ! ( schema2. types[ "Obj" ] . directives( ) . has( "dir" ) ) ;
34
- schema2 . validate ( ) . unwrap ( ) ;
53
+ validate_schema ( schema2 ) ;
35
54
}
36
55
37
56
#[ test]
@@ -47,7 +66,7 @@ fn test_orphan_extensions_schema_with_default_query_name() {
47
66
. build ( )
48
67
. unwrap ( ) ;
49
68
50
- schema . validate ( ) . unwrap ( ) ;
69
+ validate_schema ( schema ) ;
51
70
}
52
71
53
72
#[ test]
@@ -67,7 +86,7 @@ fn test_orphan_extensions_schema_def_with_extensions() {
67
86
. build ( )
68
87
. unwrap ( ) ;
69
88
70
- schema . validate ( ) . unwrap ( ) ;
89
+ validate_schema ( schema ) ;
71
90
}
72
91
73
92
#[ test]
@@ -108,7 +127,7 @@ fn test_orphan_schema_extension_with_root_type_disables_implicit_root_types() {
108
127
. unwrap ( ) ;
109
128
110
129
assert ! ( schema. schema_definition. mutation. is_none( ) ) ;
111
- schema . validate ( ) . unwrap ( ) ;
130
+ validate_schema ( schema ) ;
112
131
}
113
132
114
133
#[ test]
@@ -126,7 +145,25 @@ fn test_orphan_schema_extension_without_root_type_enables_implicit_root_types()
126
145
. unwrap ( ) ;
127
146
128
147
assert ! ( schema. schema_definition. query. is_some( ) ) ;
129
- schema. validate ( ) . unwrap ( ) ;
148
+ validate_schema ( schema) ;
149
+ }
150
+
151
+ #[ test]
152
+ fn test_orphan_schema_extension_with_directive_application ( ) {
153
+ let input = r#"
154
+ directive @something on SCHEMA
155
+ extend schema @something { query: Query }
156
+ type Query { field: Int }
157
+ "# ;
158
+
159
+ let schema = Schema :: builder ( )
160
+ . adopt_orphan_extensions ( )
161
+ . parse ( input, "schema.graphql" )
162
+ . build ( )
163
+ . unwrap ( ) ;
164
+
165
+ assert ! ( schema. schema_definition. query. is_some( ) ) ;
166
+ validate_schema ( schema) ;
130
167
}
131
168
132
169
#[ test]
0 commit comments