Skip to content

Commit

Permalink
Cache client schema exe function, and include test for unreferenced i…
Browse files Browse the repository at this point in the history
…nterface
  • Loading branch information
leebyron committed Mar 23, 2016
1 parent 37924d2 commit 1083c7e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
30 changes: 30 additions & 0 deletions src/utilities/__tests__/buildClientSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,36 @@ describe('Type System: build schema from introspection', () => {
await testSchema(schema);
});

it('builds a schema with an implicit interface', async () => {
const friendlyType = new GraphQLInterfaceType({
name: 'Friendly',
resolveType: () => null,
fields: () => ({
bestFriend: {
type: friendlyType,
description: 'The best friend of this friendly thing'
}
})
});
const dogType = new GraphQLObjectType({
name: 'Dog',
interfaces: [ friendlyType ],
fields: () => ({
bestFriend: { type: dogType }
})
});
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'WithInterface',
fields: {
dog: { type: dogType }
}
})
});

await testSchema(schema);
});

it('builds a schema with a union', async () => {
const dogType = new GraphQLObjectType({
name: 'Dog',
Expand Down
16 changes: 7 additions & 9 deletions src/utilities/buildClientSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ export function buildClientSchema(
name: interfaceIntrospection.name,
description: interfaceIntrospection.description,
fields: () => buildFieldDefMap(interfaceIntrospection),
resolveType: () => {
throw new Error('Client Schema cannot be used for execution.');
}
resolveType: cannotExecuteClientSchema,
});
}

Expand All @@ -248,9 +246,7 @@ export function buildClientSchema(
name: unionIntrospection.name,
description: unionIntrospection.description,
types: unionIntrospection.possibleTypes.map(getObjectType),
resolveType: () => {
throw new Error('Client Schema cannot be used for execution.');
}
resolveType: cannotExecuteClientSchema,
});
}

Expand Down Expand Up @@ -290,9 +286,7 @@ export function buildClientSchema(
deprecationReason: fieldIntrospection.deprecationReason,
type: getOutputType(fieldIntrospection.type),
args: buildInputValueDefMap(fieldIntrospection.args),
resolve: () => {
throw new Error('Client Schema cannot be used for execution.');
},
resolve: cannotExecuteClientSchema,
})
);
}
Expand Down Expand Up @@ -377,3 +371,7 @@ export function buildClientSchema(
directives,
});
}

function cannotExecuteClientSchema() {
throw new Error('Client Schema cannot be used for execution.');
}

0 comments on commit 1083c7e

Please sign in to comment.