It needs a mix of both or some form of suspension of disbelief to cover for one of them. If a game has a shitty story, then it feels very lackluster when you achieve something, because there is no reward. If a game has shitty gameplay, then it becomes a chore to play through, but it has it's moments. However take a good Silent Hill for example, the controls feel like you're controlling the character's ass instead of the rest of their body, but that emphasizes the scariness of the game. On the opposite side of the spectrum, Bayonetta and old DMC's have a story only set up to guide the player between fights, but the main characters maintain a joking demeanor as if they're in on the joke.
I can't think of many good RPG examples of bad gameplay right now so that's why I used two games outside of the genre for my point. I would have to say Pokemon would be an example of bad story though, I can't think of a single moment in any of their stories I felt any kind of emotion, without playing Nuzlocke, so they leave me very unsatisfied.