Skip to content

Commit 1083c7e

Browse files
committed
Cache client schema exe function, and include test for unreferenced interface
1 parent 37924d2 commit 1083c7e

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/utilities/__tests__/buildClientSchema.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,36 @@ describe('Type System: build schema from introspection', () => {
223223
await testSchema(schema);
224224
});
225225

226+
it('builds a schema with an implicit interface', async () => {
227+
const friendlyType = new GraphQLInterfaceType({
228+
name: 'Friendly',
229+
resolveType: () => null,
230+
fields: () => ({
231+
bestFriend: {
232+
type: friendlyType,
233+
description: 'The best friend of this friendly thing'
234+
}
235+
})
236+
});
237+
const dogType = new GraphQLObjectType({
238+
name: 'Dog',
239+
interfaces: [ friendlyType ],
240+
fields: () => ({
241+
bestFriend: { type: dogType }
242+
})
243+
});
244+
const schema = new GraphQLSchema({
245+
query: new GraphQLObjectType({
246+
name: 'WithInterface',
247+
fields: {
248+
dog: { type: dogType }
249+
}
250+
})
251+
});
252+
253+
await testSchema(schema);
254+
});
255+
226256
it('builds a schema with a union', async () => {
227257
const dogType = new GraphQLObjectType({
228258
name: 'Dog',

src/utilities/buildClientSchema.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ export function buildClientSchema(
235235
name: interfaceIntrospection.name,
236236
description: interfaceIntrospection.description,
237237
fields: () => buildFieldDefMap(interfaceIntrospection),
238-
resolveType: () => {
239-
throw new Error('Client Schema cannot be used for execution.');
240-
}
238+
resolveType: cannotExecuteClientSchema,
241239
});
242240
}
243241

@@ -248,9 +246,7 @@ export function buildClientSchema(
248246
name: unionIntrospection.name,
249247
description: unionIntrospection.description,
250248
types: unionIntrospection.possibleTypes.map(getObjectType),
251-
resolveType: () => {
252-
throw new Error('Client Schema cannot be used for execution.');
253-
}
249+
resolveType: cannotExecuteClientSchema,
254250
});
255251
}
256252

@@ -290,9 +286,7 @@ export function buildClientSchema(
290286
deprecationReason: fieldIntrospection.deprecationReason,
291287
type: getOutputType(fieldIntrospection.type),
292288
args: buildInputValueDefMap(fieldIntrospection.args),
293-
resolve: () => {
294-
throw new Error('Client Schema cannot be used for execution.');
295-
},
289+
resolve: cannotExecuteClientSchema,
296290
})
297291
);
298292
}
@@ -377,3 +371,7 @@ export function buildClientSchema(
377371
directives,
378372
});
379373
}
374+
375+
function cannotExecuteClientSchema() {
376+
throw new Error('Client Schema cannot be used for execution.');
377+
}

0 commit comments

Comments
 (0)