Dark matter freeze-in with a heavy mediator: beyond the EFT approach