Is it OK to have 10ga wire running from breaker to switch then 8ga from switch to pump?
You are free to use a conductor that is rated greater than the ampacity of the feed, but not less than. If the breaker is 30 amps, you can go above #10, but not below it. Likewise, if the breaker is 40 amps, you can't go smaller than #8.

If you're using #8 just to compensate for the drop over distance, then yes - you can come out of the switch with #10 if #8 somehow makes termination impractical at the pump. It's not uncommon to see #8 pulled to hot tubs and the like even with a 30A breaker simply because the electrician is not sure what kind of motor is actually going to show up, so they go with the larger conductor just in case.

This, of course is assuming copper wire with THHN insulation.