Skip to content

Commit e99fc53

Browse files
committed
Merge pull request #107 from graphql/fixinterface
Ensure unreferenced types that implement reference interfaces are detected
2 parents 8317a11 + b310921 commit e99fc53

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/utilities/__tests__/buildASTSchema.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,40 @@ type Mutation {
253253
var output = cycleOutput(body, 'HelloScalars', 'Mutation');
254254
expect(output).to.equal(body);
255255
});
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+
});
256290
});
257291

258292
describe('Schema Parser Failures', () => {

src/utilities/buildASTSchema.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,14 @@ export function buildASTSchema(
140140
};
141141
}
142142

143-
144143
var produceTypeDef = getTypeDefProducer(ast);
145144

146145
if (isNullish(astMap[queryTypeName])) {
147146
throw new Error(`Type ${queryTypeName} not found in document`);
148147
}
149148

149+
ast.definitions.forEach(produceTypeDef);
150+
150151
var queryType = produceTypeDef(astMap[queryTypeName]);
151152
var schema;
152153
if (isNullish(mutationTypeName)) {

0 commit comments

Comments
 (0)