@nestjs/graphql
Version:
Nest - modern, fast, powerful node.js web framework (@graphql)
15 lines (14 loc) • 635 B
JavaScript
import { isUndefined } from '@nestjs/common/utils/shared.utils.js';
import { isEqual } from 'es-toolkit';
import { DefaultValuesConflictError } from '../errors/default-values-conflict.error.js';
export function getDefaultValue(instance, options, key, typeName) {
const initializerValue = instance[key];
if (isUndefined(options.defaultValue)) {
return initializerValue;
}
if (!isEqual(options.defaultValue, initializerValue) &&
!isUndefined(initializerValue)) {
throw new DefaultValuesConflictError(typeName, key, options.defaultValue, initializerValue);
}
return options.defaultValue;
}