Even if the line is a hectic place of people fighting for position, if you're cemented in your spot and are friendly to the people in front/behind you, just ask them. You're in the same boat together and they'd have to use the bathroom at some point too, so just ask nicely and hope you have some humane people around you.
I've never had an issue using the restroom. Most years, my local Apple Store has even had porta poddies outback. If you have a chair, just leave your chair and go to the bathroom. Everyone around you knows that's your spot. If you have a few things (nothing too expensive) that you can't necessarily take to the restroom with you, just make some conversation with a person next to you and ask if they can just keep an eye on your stuff for a minute while you use a restroom. I've found that most people in line are decent people.