import { GraphQLError } from 'graphql';
import { SortCodesProvider } from '../providers/sort-codes.provider.js';
export const commonFinancialEntityFields = {
    sortCode: (DbBusiness, _, { injector }) => {
        if (!DbBusiness.sort_code || !DbBusiness.owner_id) {
            return null;
        }
        try {
            return injector
                .get(SortCodesProvider)
                .getSortCodesByIdLoader.load({ key: DbBusiness.sort_code, ownerId: DbBusiness.owner_id })
                .then(sortCode => sortCode ?? null);
        }
        catch (e) {
            console.error(`Error finding sort code for business id ${DbBusiness.id}:`, e);
            throw new GraphQLError(`Error finding sort code for business id ${DbBusiness.id}`);
        }
    },
};
//# sourceMappingURL=common.js.map