Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Assert(typeof fieldResolver === 'function', `${resolverName}.${fieldName} resolver must be a function`);
if (type instanceof graphql.GraphQLScalarType) {
type[fieldName] = fieldResolver;
continue;
}
if (type instanceof graphql.GraphQLEnumType) {
const fieldType = type.getValue(fieldName);
Assert(fieldType, `${resolverName}.${fieldName} enum definition missing from schema`);
fieldType.value = fieldResolver;
continue;
}
// no need to set resolvers unless we are dealing with a type that needs resolvers
if (!(type instanceof graphql.GraphQLObjectType) && !(type instanceof graphql.GraphQLInterfaceType)) {
continue;
}
const fields = type.getFields();
if (!fields) {
continue;
}
fields[fieldName].resolve = fieldResolver;
}
}
return astSchema;
};