Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.makeExecutableSchema = ({ typeDefs, resolvers = {} }) => {
const parsed = graphql.parse(typeDefs);
const astSchema = graphql.buildASTSchema(parsed, { commentDescriptions: true });
for (const resolverName of Object.keys(resolvers)) {
const type = astSchema.getType(resolverName);
Assert(type || resolverName === '__schema', `Missing schema definition for resolver: ${resolverName}`);
const typeResolver = resolvers[resolverName];
// go through field resolvers for the parent resolver type
for (const fieldName of Object.keys(typeResolver)) {
const fieldResolver = typeResolver[fieldName];
Assert(typeof fieldResolver === 'function', `${resolverName}.${fieldName} resolver must be a function`);
if (type instanceof graphql.GraphQLScalarType) {
type[fieldName] = fieldResolver;
continue;
}