@@ -88,29 +88,6 @@ class SchemaParserTests: XCTestCase {
88
88
XCTAssert ( result == expected)
89
89
}
90
90
91
- func testSimpleExtension( ) throws {
92
- let source = " extend type Hello { world: String } "
93
-
94
- let expected = Document (
95
- definitions: [
96
- TypeExtensionDefinition (
97
- definition: ObjectTypeDefinition (
98
- name: nameNode ( " Hello " ) ,
99
- fields: [
100
- fieldNode (
101
- nameNode ( " world " ) ,
102
- typeNode ( " String " )
103
- ) ,
104
- ]
105
- )
106
- ) ,
107
- ]
108
- )
109
-
110
- let result = try parse ( source: source)
111
- XCTAssert ( result == expected)
112
- }
113
-
114
91
func testParsesTypeWithDescriptionString( ) throws {
115
92
let doc = try parse ( source: """
116
93
" Description "
@@ -168,6 +145,172 @@ class SchemaParserTests: XCTestCase {
168
145
)
169
146
}
170
147
148
+ func testSimpleExtension( ) throws {
149
+ let source = " extend type Hello { world: String } "
150
+
151
+ let expected = Document (
152
+ definitions: [
153
+ TypeExtensionDefinition (
154
+ definition: ObjectTypeDefinition (
155
+ name: nameNode ( " Hello " ) ,
156
+ fields: [
157
+ fieldNode (
158
+ nameNode ( " world " ) ,
159
+ typeNode ( " String " )
160
+ ) ,
161
+ ]
162
+ )
163
+ ) ,
164
+ ]
165
+ )
166
+
167
+ let result = try parse ( source: source)
168
+ XCTAssert ( result == expected)
169
+ }
170
+
171
+ func testObjectExtensionWithoutFields( ) throws {
172
+ XCTAssertEqual (
173
+ try parse ( source: " extend type Hello implements Greeting " ) ,
174
+ Document (
175
+ definitions: [
176
+ TypeExtensionDefinition (
177
+ definition: ObjectTypeDefinition (
178
+ name: nameNode ( " Hello " ) ,
179
+ interfaces: [ typeNode ( " Greeting " ) ] ,
180
+ directives: [ ] ,
181
+ fields: [ ]
182
+ )
183
+ ) ,
184
+ ]
185
+ )
186
+ )
187
+ }
188
+
189
+ func testInterfaceExtensionWithoutFields( ) throws {
190
+ XCTAssertEqual (
191
+ try parse ( source: " extend interface Hello implements Greeting " ) ,
192
+ Document (
193
+ definitions: [
194
+ InterfaceExtensionDefinition (
195
+ definition: InterfaceTypeDefinition (
196
+ name: nameNode ( " Hello " ) ,
197
+ interfaces: [ typeNode ( " Greeting " ) ] ,
198
+ directives: [ ] ,
199
+ fields: [ ]
200
+ )
201
+ ) ,
202
+ ]
203
+ )
204
+ )
205
+ }
206
+
207
+ func testObjectExtensionWithoutFieldsFollowedByExtension( ) throws {
208
+ XCTAssertEqual (
209
+ try parse ( source: """
210
+ extend type Hello implements Greeting
211
+
212
+ extend type Hello implements SecondGreeting
213
+ """ ) ,
214
+ Document (
215
+ definitions: [
216
+ TypeExtensionDefinition (
217
+ definition: ObjectTypeDefinition (
218
+ name: nameNode ( " Hello " ) ,
219
+ interfaces: [ typeNode ( " Greeting " ) ] ,
220
+ directives: [ ] ,
221
+ fields: [ ]
222
+ )
223
+ ) ,
224
+ TypeExtensionDefinition (
225
+ definition: ObjectTypeDefinition (
226
+ name: nameNode ( " Hello " ) ,
227
+ interfaces: [ typeNode ( " SecondGreeting " ) ] ,
228
+ directives: [ ] ,
229
+ fields: [ ]
230
+ )
231
+ ) ,
232
+ ]
233
+ )
234
+ )
235
+ }
236
+
237
+ func testExtensionWithoutAnythingThrows( ) throws {
238
+ try XCTAssertThrowsError ( parse ( source: " extend scalar Hello " ) )
239
+ try XCTAssertThrowsError ( parse ( source: " extend type Hello " ) )
240
+ try XCTAssertThrowsError ( parse ( source: " extend interface Hello " ) )
241
+ try XCTAssertThrowsError ( parse ( source: " extend union Hello " ) )
242
+ try XCTAssertThrowsError ( parse ( source: " extend enum Hello " ) )
243
+ try XCTAssertThrowsError ( parse ( source: " extend input Hello " ) )
244
+ }
245
+
246
+ func testInterfaceExtensionWithoutFieldsFollowedByExtension( ) throws {
247
+ XCTAssertEqual (
248
+ try parse ( source: """
249
+ extend interface Hello implements Greeting
250
+
251
+ extend interface Hello implements SecondGreeting
252
+ """ ) ,
253
+ Document (
254
+ definitions: [
255
+ InterfaceExtensionDefinition (
256
+ definition: InterfaceTypeDefinition (
257
+ name: nameNode ( " Hello " ) ,
258
+ interfaces: [ typeNode ( " Greeting " ) ] ,
259
+ directives: [ ] ,
260
+ fields: [ ]
261
+ )
262
+ ) ,
263
+ InterfaceExtensionDefinition (
264
+ definition: InterfaceTypeDefinition (
265
+ name: nameNode ( " Hello " ) ,
266
+ interfaces: [ typeNode ( " SecondGreeting " ) ] ,
267
+ directives: [ ] ,
268
+ fields: [ ]
269
+ )
270
+ ) ,
271
+ ]
272
+ )
273
+ )
274
+ }
275
+
276
+ func testObjectExtensionDoNotIncludeDescriptions( ) throws {
277
+ XCTAssertThrowsError (
278
+ try parse ( source: """
279
+ " Description "
280
+ extend type Hello {
281
+ world: String
282
+ }
283
+ """ )
284
+ )
285
+
286
+ XCTAssertThrowsError (
287
+ try parse ( source: """
288
+ extend " Description " type Hello {
289
+ world: String
290
+ }
291
+ """ )
292
+ )
293
+ }
294
+
295
+ func testInterfaceExtensionDoNotIncludeDescriptions( ) throws {
296
+ XCTAssertThrowsError (
297
+ try parse ( source: """
298
+ " Description "
299
+ extend interface Hello {
300
+ world: String
301
+ }
302
+ """ )
303
+ )
304
+
305
+ XCTAssertThrowsError (
306
+ try parse ( source: """
307
+ extend " Description " interface Hello {
308
+ world: String
309
+ }
310
+ """ )
311
+ )
312
+ }
313
+
171
314
func testSchemeExtension( ) throws {
172
315
// Based on Apollo Federation example schema: https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/main/COMPATIBILITY.md#products-schema-to-be-implemented-by-library-maintainers
173
316
let source =
@@ -1084,13 +1227,16 @@ class SchemaParserTests: XCTestCase {
1084
1227
}
1085
1228
1086
1229
func testInputExtension( ) throws {
1087
- let source = #"extend input InputType"#
1230
+ let source = #"extend input InputType @include "#
1088
1231
1089
1232
let expected = Document (
1090
1233
definitions: [
1091
1234
InputObjectExtensionDefinition (
1092
1235
definition: InputObjectTypeDefinition (
1093
1236
name: nameNode ( " InputType " ) ,
1237
+ directives: [
1238
+ Directive ( name: Name ( value: " include " ) ) ,
1239
+ ] ,
1094
1240
fields: [ ]
1095
1241
)
1096
1242
) ,
0 commit comments