Which apiURL to use for production? (ECONNREFUSED 127.0.0.1:1337)

Yes, the app is hosted on Heroku.
I was able to solve this problem by checking my env variables on Heroku. The project was migrated from v3.6.5 to v4.5.5 and I forgot to set a new required variable.

In your particular case it look like you need to clear the Gatsby Cloud app cache because your front-end is trying to connect to localhost (127.0.0.1:1337). I would not recommend to set your API URL directly on gatsby.config.js for security reasons, instead you could use an enviroment variable to avoid publishing sensitive information.