So if you have a 31 or 22, you can swap their barrels and use the same magazines for either. You can also put 17 barrels in it, and use 9mm magazines. Obviously you would want the corresponding recoil spring for each caliber.
Glock uses the same recoil spring for all models in a given frame size. All of the subcompacts have the same recoil assembly, all of the small frame compacts have the same recoil assembly, all of the large frame compacts have the same recoil assembly, all of the small frame full size guns have the same recoil, all of the large frame full size you get it.
But you can't or shouldn't anyway use a stock 9mm barrel in one of the .40/.357 guns, you need a conversion barrel because the outer diameter of the barrel is different for the 9mms, which is why there are no 9mm-> .40/.357 barrels in existence.
The small frame compacts (19, 23, 32) and subcompacts (26, 27, 33) use the same lockup and the subs can accept compact-intended barrels just fine. The full size guns are different, and barrels designed for the 17, 22, and 31 cannot be used in the 19, 23, and 32.
The frames themselves are all the same in a given (small/large, full/compact/subcompact) size, so you can swap out a full top end to any compatible frame at will, though you may or may not want to change your ejector block if you switch from the 10mm derived small frame calibers (.40 and .357) to 9mm or vice versa, because they are slightly different.
I have used 40-9 conversion barrels with factory and Khan 9mm magazines in a 23 and 27, they worked fine, didn't have any issues because of the .40-intended ejector and extractor, though if you wanted to eventually do a full swap to 9mm, you should switch both of those to the 9mm-specific parts to ensure you've done everything you can to ensure reliability.