I have a Giant Revolt Advance 1 with SRAM Apex 1. The crank has 40 teeth. Which crankset should I buy if I want 32 teeth?
SRAM Apex 1x crank supports 44, 43 and 40 tooth rings. To get to 32 teeth you'd need a mountain bike specific crank rather than a gravel groupset crank I think.
Whichever crank you select should have appropriate chainline. Presumably you have a through axle, 142mm spacing rear hub. There are plenty of MTB cranks that provide proper chainline for that.
Apex 1x comes in either GXP for a 68mm wide shell or 68mm BB30/PF30 bottom bracket versions. What you'll need is a MTB crank that fits whichever of those two you have.
I note the SRAM NX crank supports 30 to 36 tooth rings and comes in GXP and BB30/PF30 variants and supports 63 and 73mm shells. If you have the GXP bottom bracket you may have to swap out the bottom bracket for a MTB GXP one that will fit on a 68mm shell with 2x 2.5mm spacers to work with that crank. I'm not sure how compatibility with 68 vs 73mm BB30/PF30 works, perhaps spacers are used on the axle. You can obviously look further into compatibility on the SRAM site.
Another possibility is to use a bottom bracket from Wheels Manufacturing or a similar product to convert from the frame BB standard to a different crank BB standard.