File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -253,6 +253,40 @@ type Mutation {
253
253
var output = cycleOutput ( body , 'HelloScalars' , 'Mutation' ) ;
254
254
expect ( output ) . to . equal ( body ) ;
255
255
} ) ;
256
+
257
+ it ( 'Unreferenced type implementing referenced interface' , ( ) => {
258
+ var body = `
259
+ type Concrete implements Iface {
260
+ key: String
261
+ }
262
+
263
+ interface Iface {
264
+ key: String
265
+ }
266
+
267
+ type Query {
268
+ iface: Iface
269
+ }
270
+ ` ;
271
+ var output = cycleOutput ( body , 'Query' ) ;
272
+ expect ( output ) . to . equal ( body ) ;
273
+ } ) ;
274
+
275
+ it ( 'Unreferenced type implementing referenced union' , ( ) => {
276
+ var body = `
277
+ type Concrete {
278
+ key: String
279
+ }
280
+
281
+ type Query {
282
+ union: Union
283
+ }
284
+
285
+ union Union = Concrete
286
+ ` ;
287
+ var output = cycleOutput ( body , 'Query' ) ;
288
+ expect ( output ) . to . equal ( body ) ;
289
+ } ) ;
256
290
} ) ;
257
291
258
292
describe ( 'Schema Parser Failures' , ( ) => {
Original file line number Diff line number Diff line change @@ -136,6 +136,11 @@ export function buildASTSchema(
136
136
throw new Error ( 'Nothing constructed for ' + typeName ) ;
137
137
}
138
138
innerTypeMap [ typeName ] = innerTypeDef ;
139
+ if ( astMap [ typeName ] . kind === INTERFACE_DEFINITION ) {
140
+ // Now that we've created and cached our interface, ensure
141
+ // we create all implementations to point to it.
142
+ makeInterfaceImplementations ( astMap [ typeName ] ) ;
143
+ }
139
144
return buildWrappedType ( innerTypeDef , typeAST ) ;
140
145
} ;
141
146
}
@@ -211,6 +216,16 @@ export function buildASTSchema(
211
216
return def . interfaces . map ( inter => produceTypeDef ( inter ) ) ;
212
217
}
213
218
219
+ function makeInterfaceImplementations ( inter : InterfaceDefinition ) {
220
+ var interName = inter . name . value ;
221
+ var types = ast . definitions . filter ( def => def . kind === TYPE_DEFINITION ) ;
222
+ var implementingTypes = types . filter ( def => {
223
+ var names = def . interfaces . map ( namedType => namedType . name . value ) ;
224
+ return names . indexOf ( interName ) !== - 1 ;
225
+ } ) ;
226
+ implementingTypes . forEach ( produceTypeDef ) ;
227
+ }
228
+
214
229
function makeInputValues ( values : Array < InputValueDefinition > ) {
215
230
return keyValMap (
216
231
values ,
You can’t perform that action at this time.
0 commit comments